【发布时间】:2011-05-06 08:20:50
【问题描述】:
不确定是否有人知道不断重复使用的 UITableViewCell 的数量是否存在实际限制......?首先我很清楚所有的 Obj-C / Apple 内存管理规则,(我会先说明这一点,所以我没有浪费任何人的时间,他们也没有浪费我的时间)
所以我会直接问这个......关于重用 UITableViewCell 附加的“自动释放”机制是否有一些实际限制......?因为我似乎只是在一定数量后才经历崩溃,通常超过 50 页的单元格(大约 50 页 + 50 个单元格)会被翻过来......然后不知从何而来我会遇到这个崩溃......有时永远不会完全发生,有时发生得相当频繁,具体取决于内容密度...
我自己开始手动保留和释放会更好吗? 如果是这样,是否有人有经验推荐一个释放它们的好地方..?
[tableview tableView:cellForRowAtIndexPath:]: message sent to deallocated instance 0x14e0a920
好的....我找不到与实际 UITableViewCell(单元格内容或单元格本身)有关的任何内容,但是在向控制器(实例化 UITableView 对象)添加了一些保留之后,“崩溃”神秘地停止了出现...
这就是我所做的更改。基本上我添加了三个 Retain 语句,顺便说一句,我使用了“如何”的原始示例教程 - 自称“Iphone 专家”的“UITabBarController”,但“专家”否定包含保留...... (这只是代码的适用部分......)
//initialize the UITabBarController
tabBarController = [[UITabBarController alloc] init];
TabBarControllerSet = TRUE;
//Create the first UITabBarItem
MainMessageBoard *mainMessageBoard = [[MainMessageBoard alloc] initWithController: self];
[mainMessageBoard setTitle:@"?????"];
[mainMessageBoard retain]; ////******** ADDED This RETAIN ***********
//Create the second UITabBarItem
PostNewComment *postNewComment = [[PostNewComment alloc] initWithController: self];
[postNewComment setTitle:@"????"];
[postNewComment retain]; ////******** ADDED This RETAIN ***********
//Create the third UITabBarItem
logout *Logout = [[logout alloc] initWithController: self];
[Logout setTitle:@"?????"];
[Logout retain]; ////******** ADDED This RETAIN ***********
//add the UIViewControllers to the UITabController
tabBarController.viewControllers = [NSArray arrayWithObjects:mainMessageBoard, postNewComment, Logout, nil];
[tabBarController setDelegate:self];
//release
[mainMessageBoard release];
[postNewComment release];
[Logout release];
[self.view addSubview:tabBarController.view];
【问题讨论】:
-
您能否再解释一下 - 为什么会发生崩溃?你有什么样的视图结构(哪里有 50 个页面,每个页面有 50 个单元格 - 你有 50 个不同的表格视图?)。可能发布您的 cellForRowAtIndexPath 方法...
-
为什么你认为你的代码是完美的,这是苹果的限制——发布一些代码:)
标签: iphone cocoa-touch ios uitableview autorelease