我決定使用不可重複使用的,自定義的UITableView細胞在我的項目,因爲我在每個單元上運行一個計時器,並更新一個細胞的定時器可重複使用的細胞復位所有的計時器。實際上,定時器在我的視圖控制器中運行,但輸出顯示在單元格中。但是這個問題更基本:爲什麼單元格中的UILabel文本沒有被更新?我在IB:nameLabel和timeLabel中設置了2個插座,並將它們連接到單元的頭文件,IB顯示連接的插座。但是,即使試圖將字符串移入UILabel文本字段也會導致「無」。我懷疑我正在做一些基本錯誤的事情,但我無法弄清楚。使用可重複使用的單元時沒有問題。以下是分配和初始化可變數組來保存單元格,添加單元格,然後嘗試將文字字符串移入其中的代碼部分。在NSLog語句中設置斷點顯示cell.nameLabel.text爲'nil'。任何幫助將不勝感激!我已閱讀UITableViewCell參考和編程指南,但他們只討論使用可重用單元。我認爲將'reuseIdentifier'設置爲'nil'會得到一個不可重用的單元,但我不確定。的UILabel文本不能設置
-(IBAction)addNewItem:(id)sender
{
// get a new item.
NRCItem *newItem = [[NRCItemStore sharedStore] createItem];
// set timerType to 1 (seconds) - default
newItem.timerType = 1;
// get a timer controller
NRCTimerControllerViewController *timerViewController = [[NRCTimerControllerViewController alloc]init];
// set timer controller's item
timerViewController.item = newItem;
// get a new tableViewCell
if(!_myTableViewCells){
_myTableViewCells = [[NSMutableArray alloc]init];
}
NRCItemCell *cell = [[NRCItemCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:nil];
cell.nameLabel.text [email protected]"cell";
NSLog(@"addTableViewCell cell= %@", cell);
[_myTableViewCells addObject:cell];
// push the timerViewController onto the navigation controller's stack
[self.navigationController pushViewController:timerViewController animated:YES];
}
輸入代碼在這裏
你可以顯示你的'cellForRowAtIndexPath'方法嗎?順便說一句,正確的方法是您需要將您的數據模型從單元中分離出來。例如,使用一個NSNumber數組,每個數字代表一行中的已用時間。在一個定時器方法中更新所有計數,並使用'cellForRowAtIndexPath'來檢索顯示的單元格並更新它們。 – Paulw11
這是現在正在工作的代碼。我不確定發生了什麼變化,但也許我沒有設置代理來設置標籤文本。 –