2012-06-25 35 views
0

我有一個tableView與3個單元格。更改TableView協議之外的UITableViewCell.detailTextLabel

我想在tableView加載後更改該單元格的.detailTextLabel。

我該怎麼做?

我三元組這樣的:

的UITableViewCell * firstCell = [的tableView的cellForRowAtIndexPath:0];

firstCell.detailTextLabel.text = @「ABC」;

[tableView reloadData];

但這並非無所事事。什麼問題?

回答

1

,而不是

UITableViewCell *firstCell = [tableView cellForRowAtIndexPath:0]; 

使用

UITableViewCell *firstCell = [tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]]; 
+0

這不起作用。沒有什麼改變。 – theShay

0

試試這個:

UITableViewCell *firstCell = [tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]]; 

firstCell.detailTextLabel.text = @"ABC"; 

不需要調用reloadData。

+0

這是行不通的。沒有什麼改變。 – theShay

+0

你有沒有評論[tableView reloadData];以及更改detailTextLabel的位置,因爲如果在調用tableview委託方法之前更改,則cellForRowAtIndexPath將覆蓋您的值。 –

+0

我調用了我的tableView委託方法後調用它。 – theShay

0

當你說

[的tableView reloadData];

那個時候你: -

(UITableViewCell的*)的tableView:(UITableView的*)的tableView的cellForRowAtIndexPath:(NSIndexPath *)indexPath;

方法被調用三次,你有你的行中的3單元,這將再次覆蓋與您必須通過陣列提供的原文您firstCell.detailTextLabel.text ...

所以如果你正在使用數組..那麼你需要改變該數組中的對象所需的索引。

只是實現此:

[陣列replaceObjectAtIndex:0 withObject:@ 「更改」];

[tableViewCategory reloadData];

希望所以這會適合你...

+0

這不是陣列.... – theShay