0

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;
}
Community
  • 1
  • 1
Destiny Dawn
  • 1,457
  • 3
  • 15
  • 29

4 Answers4

1

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.

Rok Jarc
  • 18,765
  • 9
  • 69
  • 124
0

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;
}
Mark McCorkle
  • 9,349
  • 2
  • 32
  • 42
0

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;
JeffN
  • 1,575
  • 15
  • 26
  • That appears to be set up correctly, you will want to look at asynchronous loading of your data. Are you using standard Apple Networking for your data? Look into a library called AFNetworking on Github – JeffN Apr 22 '13 at 21:25
0

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.

Hal Mueller
  • 7,019
  • 2
  • 24
  • 42