2011-05-06 149 views
0

不知道是否有人知道是否存在實際限制的UITableViewCells數量不斷被重新利用......?首先,我很清楚所有的Obj-C/Apple內存管理規則(我會首先說明,所以我不會浪費任何人的時間,也不會浪費我的)UITableViewCell AutoRelease導致崩潰...?

所以我會問這個問題out ...是否存在一些關於重用UITableViewCell的「Autorelease」機制的實際限制..?因爲我似乎只是經歷了一定數量的崩潰,所以通常超過50頁的單元格(大約50頁+ 50單元格)被翻上......然後出於否定 - 我會在這裏崩潰..有時從不發生在所有的,有時會發生相當頻繁,這取決於內容密度...

它會更好手動啓動保持和釋放我自己..? 如果是這樣,有人會有經驗推薦一個好地方釋放他們..?

[tableview tableView:cellForRowAtIndexPath:]: message sent to deallocated instance 0x14e0a920 

好吧....我沒能找到任何與實際的UITableViewCell(單元格內容或細胞本身),但增加後的數保留到控制器(其實例化的UITableView對象)的「撞車」神祕就不來了......

這裏是我的改變。基本上,我添加了三個Retain語句,順便說一下,我使用了自定義的「Iphone專家」中的「How To」 - 「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]; 
+2

你能解釋一下多一點 - 爲什麼正是你得到一個崩潰?你有什麼樣的視圖結構(50個頁面各有50個單元 - 你有50個不同的表格視圖?)。也許發表您的cellForRowAtIndexPath方法... – Vladimir 2011-05-06 08:25:52

+1

爲什麼你認爲你的代碼是完美的,它是一個蘋果的限制 - 發佈一些代碼:) – deanWombourne 2011-05-06 09:10:17

回答

1

據我所知它是由在設備上釋放內存只有有限的 - 我假設它使用的自動釋放池某種動態組和在表格視圖的可重複使用的單元格中(即NSSet或更低級別的等效單元格)。

我用用行數萬表視圖沒有任何問題。

+0

謝謝...那麼它一定是在我結束的東西.... – NpC0mpl3t3 2011-05-09 23:17:10

+0

會缺乏TabBarController上的「retain」導致TableViewController將轉儲作爲:tableview tableView:cellForRowAtIndexPath:]:發送到釋放實例0x14e0a920的消息...?我添加了一個保留,現在我處理/重用了超過4500個單元格,但沒有發生任何事件(截至目前爲止......)...儘管類似這樣的崩潰必須由更加惡毒的事情引起,比如明確地釋放在使用或類似的...? – NpC0mpl3t3 2011-05-10 07:08:37

+0

好吧,如果你的tabBarController被autoreleased,那麼它會被釋放,而不是你;)聽起來像是這個問題,很好的工作! – deanWombourne 2011-05-10 08:54:09