Re: iPhone: load cell from XIB slows down tableview?

2010-01-04 Thread Damien Cooke


John,
I had a similar issue. For me the problem turned out to be that the  
reusableId was not being set as it was imported from the nib. Thus the  
call dequeue one was always retuning nil.  I solved this by building  
the cell by hand and calling the correct init method so the reusableid  
was being set and all works well now. Let me know if there is a better  
solution.


Regards
Damien

Sent from my iPhone 3GS

On 04/01/2010, at 3:33 PM, John Michael Zorko jmzo...@mac.com wrote:



Hello, all ...

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;

   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;
   }
   }
  }

   MyObject *act = nil;

   switch(indexPath.section)
   {
   case 0:
   act = [appDelegate array1ItemAtIndex:indexPath.row];
   cell.type = 2;
   break;
   case 1:
   act = [appDelegate array2ItemAtIndex:indexPath.row];
   cell.type = 3;
   break;
   case 2:
   act = [appDelegate array3ItemAtIndex:indexPath.row];
   cell.type = 4;
   break;
   case 3:
   act = [appDelegate array4ItemAtIndex:indexPath.row];
   cell.type = 5;
   break;
   }

   cell.name.text = act.name;
   cell.label1.text = [NSString stringWithFormat:@%i,  
act.anNSString];

   cell.field1.text = @;
   cell.field2.text = @;
   cell.ident = indexPath.row;
   [cell.deleteButton removeFromSuperview];

  return cell;
}

Regards,

John
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/damien%40smartphonedev.com

This email sent to dam...@smartphonedev.com

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: iPhone: load cell from XIB slows down tableview?

2010-01-04 Thread Tony Ingraldi
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 (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: iPhone: load cell from XIB slows down tableview?

2010-01-04 Thread John Michael Zorko


Tony,

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.


I fixed the issue last night, perhaps 20 minutes after I posted the  
question. Yes, it was exactly as you described -- I had the ID set  
incorrectly in the XIB. Many thanks!


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.


That is a good idea -- i'll try it :-)

Regards,

John

Falling You - exploring the beauty of voice and sound
http://www.fallingyou.com











___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


iPhone: load cell from XIB slows down tableview?

2010-01-03 Thread John Michael Zorko

Hello, all ...

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;

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;
}
}
   }

MyObject *act = nil;

switch(indexPath.section)
{
case 0:
act = [appDelegate array1ItemAtIndex:indexPath.row];
cell.type = 2;
break;
case 1:
act = [appDelegate array2ItemAtIndex:indexPath.row];
cell.type = 3;
break;
case 2:
act = [appDelegate array3ItemAtIndex:indexPath.row];
cell.type = 4;
break;
case 3:
act = [appDelegate array4ItemAtIndex:indexPath.row];
cell.type = 5;
break;
}

cell.name.text = act.name;
cell.label1.text = [NSString stringWithFormat:@%i, act.anNSString];
cell.field1.text = @;
cell.field2.text = @;
cell.ident = indexPath.row;
[cell.deleteButton removeFromSuperview];

   return cell;
}

Regards,

John
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com