Re: iPhone: load cell from XIB slows down tableview?
Re: iPhone: load cell from XIB slows down tableview?
- Subject: Re: iPhone: load cell from XIB slows down tableview?
- From: Tony Ingraldi <email@hidden>
- Date: Mon, 4 Jan 2010 08:51:22 -0500
On Jan 4, 2010, at 12:03 AM, John Michael Zorko wrote:
> I'm trying to determine why my tableviews scroll so jerkily on non-3GS devices. The datasource only has perhaps 170 records, so I think it may have something to do with how i'm instantiating the cells in -tableView:cellForRowAtIndexPath. In other apps i've done, I create the view for the cell programmatically, and alloc / init the cell if I can't dequeue it. However, in this app, I have the cell's view loaded from a XIB. Is there a better way of defining my cell's view with IB that still results in a performant tableview?
>
> - (UITableViewCell *)tableView:(UITableView *)tableViewIn cellForRowAtIndexPath:(NSIndexPath *)indexPath
> {
> static NSString *cellID = @"mycellID";
>
Have you verified that you've set the Identifier for the custom cell in the XIB to match the above cellID? If they don't match, you'll end up loading the XIB for every row in the table view. If things are set up properly, the XIB will be loaded once for each visible row on the screen plus a few more depending on how fast you scroll.
> MyAppDelegate *appDelegate = (MyAppDelegate *)[[UIApplication sharedApplication] delegate];
>
> LogDailyCell *cell = (LogDailyCell *)[tableViewIn dequeueReusableCellWithIdentifier:cellID];
>
> if (nil == cell)
> {
> NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"LogDailyCell"
> owner:self options:nil];
> for (id oneObject in nib)
> {
> if ([oneObject isKindOfClass:[LogDailyCell class]])
> {
> cell = (LogDailyCell *)oneObject;
> break;
> }
> }
> }
This is less of an issue, but iterating over the objects in the XIB can be avoided by adding an outlet connected to the custom cell to your class that owns the XIB. I've got a sample project that demonstrates this available at
http://majestysoftware.com/code/CustomCellFromNib.zip
The project was created pre-3.0, so you'll get a deprecation warning when building. The basic concept is still valid in 3.x.
--
Tony Ingraldi
http://www.majestysoftware.com/
Old-fashioned values and high-tech know-how_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden