I'm an Irish iPhone developer, currently migrating my skills from the web to Apples most popular mobile computing device. Based in County Leitrim, Ireland and working from home as a freelance developer in PHP, Perl, and Objective-C.

Contact me at andy@luibh.ie.

UITableView Selection Smoothing

If you use table views, and you need to smooth the transition a little bit when selecting a row and pushing a view controller, I’d recommend looking into ‘performSelector’. Its basically a timer which allows you to call a method after a certain short delay.

When using table views this gives the selected row enough time fully animate the selection, before moving onto the new view.

// our own method called from the performSelector
- (void)didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
	MarketViewController *market = [[MarketViewController alloc] 
		initWithNibName:@"MarketViewController" bundle:nil];		
	market.eventMarket = [self.eventMarkets objectAtIndex:indexPath.row-1];
	market.title = [[self.eventMarkets objectAtIndex:indexPath.row-1] marketName];
	[self.navigationController pushViewController:market animated:YES];		
	[market release];		
}

// delegate method for table
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
	[self performSelector:@selector(didSelectRowAtIndexPath:) withObject:indexPath 
		afterDelay:0.1f];
}

Something else I just realised is that my tableviews weren’t automatically deselecting the rows when I returned from the push view controller. The following code rectifies that nicely (and smoothly).

-(void)viewDidAppear:(BOOL)animated {
	[tableMarkets deselectRowAtIndexPath:[tableMarkets indexPathForSelectedRow] 
		animated:animated];	
}