0
votes

I have a simple UITableView using custom UITableViewCells. The options set on the UITableView's properties are only that the style is set to Grouped. When I'm trying to scroll down through the different items the scroll is extremely jumpy. I've researched this quite a bit looking at Tricks for improving iPhone UITableView scrolling performance? and a few other questions on this website. I haven't really been able to find a solution though.

EDIT **** I use a WSDL webservice to load data into the UITableViewCells. The cells only have a UITextView and three buttons in it.

EDIT ****

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *CellIdentifier = @"NavigatorCell";

    NewCell *cell = (NewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"NewCell" owner:self options:nil];
        cell = [nib objectAtIndex:0];
    }

    cell.postId = [[items objectAtIndex:indexPath.row] objectForKey:@"PostID"];
    cell.post.text = [[items objectAtIndex:indexPath.row] objectForKey:@"Post"];

    return cell;
}
4
Is your tableview set to reuse cells? - JeffN
what do you load into the cells? - holex
@DCS123 how do I set that? - Destiny Dawn
Will add answer below. - JeffN
@holex please see the updated question. - Destiny Dawn

4 Answers

1
votes

I see your NewCell is subclassed.

Don't forget to include this method into your NewCell.m

- (NSString *) reuseIdentifier
{    
    return @"Cell Identifier";
}

Of course @"Cell Identifier" should be the same that you use in your cellForRowAtIndexPath:. If you fail to implement this method each cell will be generated from scratch.

0
votes

Are you using a dequeReusableCellWithIdentifier? Follow the format below. Since you now mention you are loading data from the web you need to do this asynchronously to allow for smooth scrolling. To load from a webservice (asynchronously) there is a nice project just for that here

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath     *)indexPath
{
    static NSString *CellIdentifier = @"yourCellName";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

    return cell;
}
0
votes

Setting your tableview to Reuse cells is the most basic way to ensure good performance. Basically it means that instead of creating a new cell for every cell in the tableview, your tableview will recycle the cells that are off screen. The basic setup is below, and more can be learned from the apple documentation on UITableViewDelegate linked here

       - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
        {
            NSString *CellIdentifier = @"Cell Identifier";

            CustomCellClassName *cell = (CustomCellClassName *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];

                if (cell == nil){
                    cell = [[CustomCellClassName alloc] initWithFrame:CGRectMake(0, 0, tableView.frame.size.width, tableView.frame.size.height)];
                    //Do basic cell construction common to all cells of this type here
                    //Set background, image etc.  
                }



                //Do specific cell construction here
                return cell;
0
votes

If you're loading data over the network for each cell, you'll see poor performance. Batch your data fetch, then when it's ready tell your tableview to reload itself.

Using Core Data as a temporary backing store, and an NSFetchedResultsController to retrieve the info from Core Data, will save you some work.