开发者

iPHONE: TableView Scroll isn't smooth - What could be wrong?

开发者 https://www.devze.com 2023-02-09 21:41 出处:网络
I have a table view as shown. It displays various European Languages from database. When I scroll the tableview the scrolling isn\'t smooth and at times it gets stuck for a second or two. What could b

I have a table view as shown. It displays various European Languages from database. When I scroll the tableview the scrolling isn't smooth and at times it gets stuck for a second or two. What could be wrong?

I am decoding the languages using below code:

NSString *cellText 开发者_高级运维= [[langArray objectAtIndex:i] valueForKey:[NSString stringWithFormat:@"%@",lblshortName.text]];
    
    if (cellText != (NSString *)[NSNull null] && ![cellText isEqualToString:@""] ) {
        NSString *decodedString3 = [NSString stringWithUTF8String:[cellText cStringUsingEncoding:[NSString defaultCStringEncoding]]];
        
        [cellTextArray addObject:[NSString stringWithFormat:@"%@ : %@",lblshortName.text, decodedString3]];
    }
    else {
        [cellTextArray addObject:@"<empty>"];
    }

iPHONE: TableView Scroll isn't smooth - What could be wrong?


I would suggest to do few things..

  1. Check if you are reusing the Cell, if you are then cross check it's working by putting counter for every new cell.

  2. Use static analyzer and instruments for checking any potential leaks, memory allocations and objects are being freed or not.

if everything is fine.. then it's hard to say anything without seeing other part of the code.. one more thing you can do is using asynchronous thread to get data ready for the table view.


It would help if you provide more code, in particular how you use table-view cells, because table-view cells can easily cause performance issues.

Regarding your code, it seems like that the entire cellTextArray is built before presenting the table view, say, when you initialize the data source of the table view. Correct? Pre-building data could be good for the performance in general, but if the array is really, really huge so it causes a memory problem, then you might want to build texts dynamically.

More likely, however, I would check the followings first :

  1. Are table-view cells property being reused?
  2. Are subviews in the table-view cell opaque?
  3. Aren't table-view cells drawing the entire region every time?
  4. Aren't you unnecessarily calling drawRect: method directly?


I have seen such behavior when .layer property is being used in a lot places so, are you accessing the .layer property of a subview in the table cell or so?

0

精彩评论

暂无评论...
验证码 换一张
取 消