UITableView scrolling madness

I have a table view which gets data from a core data array. When I try to assign the value of the object “Post” to something or NSLog it the table scrolling lags.

Here is my code:

  • How can I dismiss the keyboard if a user taps off the on-screen keyboard?
  • Xcode 6 auto layout programmatically?
  • How to check internet connection in Swift 3 or Swift 4?
  • How to tell what profile/signing certificate was used to sign .ipa?
  • Change app language in iOS without restarting the app
  • Reference from UITableViewCell to parent UITableView?
  • - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
        static NSString *CellIdentifier = @"CellCell";
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    
        Post *post = [array objectAtIndex:indexPath.row];
        // If I comment out the NSLog the scroll is smoothly
        NSLog(@"%@", post.title);    
        // Same thing for the line below
        cell.textLabel.text = post.title;
        return cell;
    }
    

    EDIT:

    I’m using StackMob v1.2.0

    2 Solutions Collect From Internet About “UITableView scrolling madness”

    Using NSLog will surely cause performance issues, especially in methods like cellForRowAtIndexPath which is invoked frequently.

    Please check these article for details :

    1. Dropping NSLog in release builds
    2. The Evolution of a Replacement for NSLog

    EDIT :

    Also your implementation causes the slowness.

    You are missing the allocation of tableviewCells.

     UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
     if(cell == nil)
     {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
     }
    

    First of all you should add the code that “Midhun MP” proposed.

    If this doesnt help with the lagging problem…then i suppose post.title must be too heavy to be in that method (because that method gets called too many times)(Please let it not be that post.title uses internet connection to get the string?! Is it?)

    Solution:
    1)First thing in your app : Create an array2 and put in there all the post.title that u need(every time posts change you shoud update that array2)
    2)use this array2 to get the text for the cells : cell.textLabel.textPost=[array2 objectAtIndex:indexPath.row];
    3)I cant be 100% sure if NSLog is a problem because i havent tested that(could be..but this should only occur during debug…in release mode you shouldnt have it in there) but its easy to test and see(just comment the NSLog line)

    Hope that helps.