iPHONE: TableView Scroll isn't smooth - What could be wrong?
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>"];
}
I would suggest to do few things..
Check if you are reusing the Cell, if you are then cross check it's working by putting counter for every new cell.
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 :
- Are table-view cells property being reused?
- Are subviews in the table-view cell opaque?
- Aren't table-view cells drawing the entire region every time?
- 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?
精彩评论