1
- (void)viewDidLoad {
    [super viewDidLoad];
    [self.tableView setRowHeight:100];
    [self.tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
    [self.view setBackgroundColor:[UIColor groupTableViewBackgroundColor]];
}


#pragma mark -
#pragma mark Table view data source

// Customize the number of sections in the table view.
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}


// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 3;
}


// 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] initWithFrame:CGRectMake(0, 0, 320, 100) reuseIdentifier:CellIdentifier] autorelease];

        // For Name/Phone: 
        UITextField *name = [[[UITextField alloc] initWithFrame:CGRectMake(75, 22, 200, 25)] autorelease];
        [name setFont:[UIFont systemFontOfSize:14]];
        [name setPlaceholder:@"John Doe"];
        [name setReturnKeyType:UIReturnKeyDone];
        [name setAutocapitalizationType:UITextAutocapitalizationTypeWords];
        [name setAutocorrectionType:UITextAutocorrectionTypeNo];
        [name setContentVerticalAlignment:UIControlContentVerticalAlignmentCenter];

        UITextField *phone = [[[UITextField alloc] initWithFrame:CGRectMake(75, 67, 200, 25)] autorelease];
        [phone setFont:[UIFont systemFontOfSize:14]];
        [phone setPlaceholder:@"0412 123 123"];
        [phone setReturnKeyType:UIReturnKeyDone];
        //[phone setKeyboardType:UIKeyboardTypePhonePad];
        [phone setContentVerticalAlignment:UIControlContentVerticalAlignmentCenter];

        UIImageView *background = [[[UIImageView alloc] initWithFrame:CGRectMake(9, 11, 302, 89)] autorelease];
        background.image = [UIImage imageNamed:@"book-personaldetailsbg.png"];

        // Add to the View
        [cell addSubview:background];
        [cell addSubview:name];
        [cell addSubview:phone];

        // Add actions:
        [name addTarget:self action:@selector(textFieldDone:) forControlEvents:UIControlEventEditingDidEndOnExit]; 
        [phone addTarget:self action:@selector(textFieldDone:) forControlEvents:UIControlEventEditingDidEndOnExit]; 

    }

    return cell;
}

Is there a reason for this? I only have a few objects set up so I can hardly see why it would be lagging. It jumps, and its not my phone because the settings app works fine.

Zac Altman
  • 1,215
  • 4
  • 25
  • 37
  • does it work ok in the simulator? – curv Feb 15 '10 at 13:17
  • yep, works perfect in the simulator. Also works great on the 3GS. Its not so slow that it makes the app unusable, it just has noticeable lag which is really annoying - and would make for a much better user experience if fixed. – Zac Altman Feb 15 '10 at 13:21
  • Estimation of height for each cell could have the same effect too, please check this topic too http://stackoverflow.com/questions/21577976/uitableview-takes-much-longer-to-load-when-numberofrows-returns-a-large-number – Soheil Novinfard Feb 03 '16 at 08:17

4 Answers4

10

UITableViewCells with many subviews are slow to render on the iPhone because of the way the phone renders each layer.

Read this: http://blog.atebits.com/2008/12/fast-scrolling-in-tweetie-with-uitableview/

The information in the above post is still hugely relevant and helpful, but the example project download link is broken (as of Dec 8th 2011). However, Apple's own table view documentation has had examples of flat table cells for fast scrolling for a log while now. Check it out: http://developer.apple.com/library/ios/#samplecode/AdvancedTableViewCells/Introduction/Intro.html

The main points are:

  • The iPhone doesn't handle Alpha very quickly
  • Subviews should have their opaque property set to YES
  • If possible, draw your subviews into a single opaque view for best performance.

Obviously, cells with controls that need to be manipulated can't be flattened, so I think you'll just have to try and get away with making sure your cell subviews are opaque.

The last thing I would suggest is to not allocate new objects every time a cell is requested - this is certainly a bottleneck in your code. You should use reusable cells, and subclass a cell so that its fields are allocated and added as subviews only the first time they are created. Subsequent calls should dequeue the cell and use prepareForReuse to clear its old values.

Jasarien
  • 58,279
  • 31
  • 157
  • 188
0

I thought you aren't supposed to set the cell height like you are. I believe you should implement the heightForCellAtIndexPath method (might not have that name 100% right) and it asks your delegate how tall it should make each individual cell. I feel that I've heard of performance issues if not done the "proper" way. IMHO

The first thing I'd try if I were you is to comment out all the image related code and see if the table speeds up drastically.

jamone
  • 17,253
  • 17
  • 63
  • 98
  • ok, swapped it out for - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath - it is pretty much the same. – Zac Altman Feb 15 '10 at 13:46
  • Yes it seems the same, but from what I've seen around the interwebs this method will give you less issues down the road. – jamone Feb 15 '10 at 15:48
  • heightForCellAtIndexPath is useful for returning variable height cells, but when you have static height cells, it doesn't matter whether you use this method or set the row height property on the table view. – Jasarien Feb 15 '10 at 15:51
0

Start by removing that cell background. See if that makes a difference.

Stefan Arentz
  • 34,311
  • 8
  • 67
  • 88
0

Here the solution guys, Inside the block add the images to load and that's it:

dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0ul);
    dispatch_async(queue, ^{
        NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:
                                                      [[feeds objectAtIndex:indexPath.row]
                                                       objectForKey: @"url"]]];
        UIImage *image = [UIImage imageWithData:data];
        dispatch_async(dispatch_get_main_queue(), ^{
            cell.imagen.image = image;
        });

Use Grand Central Dispatch for priority. I can explain if anybody want, just email me at info@tonymedrano.com