Enable any class to be an UITableView delegate+datasource” script.
Problem:
your class has to support the UITableView delegate and/or datasource and is a simple UITableViewController os NSobject subclass.
Description:
While developing on the iPhone, using XCode, I found really annoying to recreate all the uitableview delegate and datasource methods if the class was before an NSObject or a UIViewController without any table, for now the only way was to do a copy and paste from another class or to create a new one class that is a subclass of UITableViewController.
The Solution:
- XCode: goto Scripts menu->Edit User Scripts

- Create a new Script

- Insert the following Code:
#! /usr/bin/perl –w
-
-
# Insert UITableView default methods (delegate and datasource) into a class.
-
# insertTableViewMethod.pl — inserts delegate and datasource methods into a class.
-
-
use strict;
-
print ”
-
#pragma mark Table view methods
-
-
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
-
return 1;
-
}
-
-
// Customize the number of rows in the table view.
-
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
-
return 0;
-
}
-
-
// Customize the appearance of table view cells.
-
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
-
static NSString *CellIdentifier = @\“Cell\”;
-
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
-
if (cell == nil) {
-
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
-
}
-
// Set up the cell…
-
return cell;
-
}
-
-
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
-
// Navigation logic may go here. Create and push another view controller.
-
// AnotherViewController *anotherViewController = [[AnotherViewController alloc] initWithNibName:@\“AnotherView\” bundle:nil];
-
// [self.navigationController pushViewController:anotherViewController];
-
// [anotherViewController release];
-
}
-
-
/*
-
// Override to support conditional editing of the table view.
-
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
-
// Return NO if you do not want the specified item to be editable.
-
return YES;
-
}
-
*/
-
-
/*
-
// Override to support editing the table view.
-
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
-
if (editingStyle == UITableViewCellEditingStyleDelete) {
-
// Delete the row from the data source
-
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:YES];
-
}
-
else if (editingStyle == UITableViewCellEditingStyleInsert) {
-
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
-
}
-
}
-
*/
-
-
/*
-
// Override to support rearranging the table view.
-
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
-
}
-
*/
-
-
/*
-
// Override to support conditional rearranging of the table view.
-
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
-
// Return NO if you do not want the item to be re-orderable.
-
return YES;
-
}
-
*/
-
“;
-
-
exit 0;
-
- Have –quick-fun!


![[Google]]( http://www.leganza.it/wp-content/plugins/easy-adsenser/google-light.gif)

Are you a manga designer? Why don’t help me develop iPhone applications?