Enable any class to be an UITableView delegate+datasource” script.

Prob­lem:

your class has to sup­port the  UITable­View del­e­gate and/or data­source and is a sim­ple UITable­View­Con­troller os NSob­ject subclass.

Descrip­tion:

While devel­op­ing on the iPhone, using XCode,  I found really annoy­ing to recre­ate all the uitable­view del­e­gate and data­source meth­ods if the class was before an NSOb­ject or a UIV­iew­Con­troller with­out any table, for now the only way was to do a copy and paste from another class or to cre­ate a new one class that is a sub­class of UITableViewController.

The Solu­tion:

  1. XCode: goto Scripts menu->Edit User Scripts
  2. Cre­ate a new Script
  3. Insert the fol­low­ing Code:
    #! /usr/bin/perl –w
    1.  
    2. # Insert UITable­View default meth­ods (del­e­gate and data­source) into a class.
    3. # insertTableViewMethod.pl — inserts del­e­gate and data­source meth­ods into a class.
    4.  
    5. use strict;
    6. print
    7. #pragma mark Table view methods
    8.  
    9. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    10. return 1;
    11. }
    12.  
    13. // Cus­tomize the num­ber of rows in the table view.
    14. - (NSInteger)tableView:(UITableView *)table­View numberOfRowsInSection:(NSInteger)section {
    15. return 0;
    16. }
    17.  
    18. // Cus­tomize the appear­ance of table view cells.
    19. - (UITable­View­Cell *)tableView:(UITableView *)table­View cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    20. sta­tic NSString *Cel­lI­den­ti­fier = @\“Cell\”;
    21. UITable­View­Cell *cell = [table­View dequeueReusableCellWithIdentifier:CellIdentifier];
    22. if (cell == nil) {
    23. cell = [[[UITable­View­Cell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    24. }
    25. // Set up the cell…
    26. return cell;
    27. }
    28.  
    29. - (void)tableView:(UITableView *)table­View didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    30. // Nav­i­ga­tion logic may go here. Cre­ate and push another view controller.
    31. // Anoth­erView­Con­troller *anoth­erView­Con­troller = [[Anoth­erView­Con­troller alloc] initWithNibName:@\“Anoth­erView\” bundle:nil];
    32. // [self.navigationController pushViewController:anotherViewController];
    33. // [anoth­erView­Con­troller release];
    34. }
    35.  
    36. /*
    37. // Over­ride to sup­port con­di­tional edit­ing of the table view.
    38. - (BOOL)tableView:(UITableView *)table­View canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    39. // Return NO if you do not want the spec­i­fied item to be editable.
    40. return YES;
    41. }
    42. */
    43.  
    44. /*
    45. // Over­ride to sup­port edit­ing the table view.
    46. - (void)tableView:(UITableView *)table­View commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    47. if (edit­ingStyle == UITableViewCellEditingStyleDelete) {
    48. // Delete the row from the data source
    49. [table­View deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:YES];
    50. }
    51. else if (edit­ingStyle == UITableViewCellEditingStyleInsert) {
    52. // Cre­ate a new instance of the appro­pri­ate class, insert it into the array, and add a new row to the table view
    53. }
    54. }
    55. */
    56.  
    57. /*
    58. // Over­ride to sup­port rear­rang­ing the table view.
    59. - (void)tableView:(UITableView *)table­View moveRowAtIndexPath:(NSIndexPath *)fro­mIn­d­ex­Path toIndexPath:(NSIndexPath *)toIndexPath {
    60. }
    61. */
    62.  
    63. /*
    64. // Over­ride to sup­port con­di­tional rear­rang­ing of the table view.
    65. - (BOOL)tableView:(UITableView *)table­View canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
    66. // Return NO if you do not want the item to be re-orderable.
    67. return YES;
    68. }
    69. */
    70. ;
    71.  
    72. exit 0;
  4. Have –quick-fun!

Io Programmo 148



In questo numero ben tre articoli:

1) inter­vista Bjarne Strous­trup: di mia inizia­tiva (e di nes­sun altro, come forse si potrebbe evin­cere da alcune frasi inserite non dal sot­to­scritto) ho con­tat­tato Bjarne Strous­trup e gli ho richiesto un’intervista via email, è stsato molto cortese e me l’ha concessa.

2) iPhone: questa vosta si parla dell’accelerometro

3) Go– il lin­guag­gio di pro­gram­mazione nato in casa Google: vor­rei pre­cis­are che non con­siglio a nes­suno di uti­liz­zare questo lin­guag­gio poichè è troppo sper­i­men­tale, ma per diver­tirsi qualche ora merita
.

Io Programmo 147

In questo arti­colo ho trat­tato di NSTimer, NSDate e di come eseguire sem­plici suoni.

E’ inoltre pre­sente un arti­colo su Mono, frame­work che con­sente di eseguire .Net su piattaforme non microsoft.

iPhone SDK 3.x — UIWebView issue: copy:selector

Inside the -(BOOL)canPerformAction:(SEL)action withSender:(id)sender method

when hold­ing the mouse pointer in the sim­u­la­tor on a word of a web­page loaded on a uiwe­b­view this method is called prop­erly, but the copy: selec­tor isn’t ana­lyzed and not even called (but the text is nor­maly copied) , I’ve opened a ticket o Apple Bug Report.

This bug don’t allow to fully dis­able the con­tex­tual menu on uiwe­b­view, and the only solu­tion is to dis­able all using javascript on the  loaded page.

Windows 7 and coninuos rebot updates

These weeks Win­dows 7 finds a new update(s) quite every week and asks to reboot, nice fea­ture, this means a much secure os, but the con­tinue reboots is becom­ing really annoy­ing, i keep my pc turned on to avoid shutdown/reboot times and now it’s useless…

Mac Users: ntfs-3g may harm your ntfs drive

I dis­cov­ered that ntfs-3g (cur­rent ver­sion) , an appli­ca­tion that allows to write on ntfs par­ti­tions is really buggy, it cor­rupted some exter­nal ntfs usb dri­ves i own, and in win­dows they became unread­able (it asks to for­mat them!).

The only solu­tion to fix this issue was to remove these dri­vers, and use paragon ntfs. I man­aged also to repair those dri­ves using the disk util­ity appli­ca­tion after unin­stalling ntfs-3g, because before its fea­tures didn’t work.

←Older