开发者

iPhone: UTableView with Uses More Memory with UITableViewStyleGrouped than with UITableViewStylePlain

开发者 https://www.devze.com 2022-12-25 17:16 出处:网络
I\'m using an UITableView with style UITableViewStyleGrouped initialized as follows: CGRect imgFrame = CGRectMake(0, 0, 320, 650);

I'm using an UITableView with style UITableViewStyleGrouped initialized as follows:

CGRect imgFrame = CGRectMake(0, 0, 320, 650);
UITableView *myTable = [[UITableView alloc] initWithFrame:imgFrame style:UITableViewStyleGrouped];
myTable.dataSource = self;
myTable.delegate = self; //make the current object the event handler for view
[self.view addSubview:myTable];
[myTable release];

The data for the table is stored in an array dataArray. dataArray itself is a collection of arrays where each array represent a section of the table. Currently I have only one section with 100 records/rows.

When I installed the app onto my IPhone, I observed that this UI开发者_Python百科TableView consumed 20 MB of iPhone memory. If I changed the table view style to UITableViewStylePlain, then it consumes only 4MB of memory.

What is wrong with "UITableViewStyleGrouped"?

Regards, prathumca.


There is nothing obviously wrong with your code. The most likely cause of your problem is the improper reuse of cells.

Check your logic in -tableview:cellForRowAtIndexPath:. I think you will find that when you have the style set to plain, you properly reuse cells but when you have it set to grouped you are creating new cells every time. The new cells pile up in memory.

0

精彩评论

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

关注公众号