2014-07-08 19 views
0

我使用willSelectRowAtIndexPath委託方法來改變所選擇的小區的detailTextLabel,亦即,i分配\U0001F44D到所選擇的小區的detailTextLabel.text並分配@""到先前選擇的小區,則問題是,先前的小區被分配@""\U0001F44D沒有出現新選擇的小區上,代碼如下:willSelectRowAtIndexPath不改變detailTextLabel

-(NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
NSIndexPath *index = [NSIndexPath indexPathForRow:self.selectedCalcMethod inSection:0]; // index of previously selected cell 

    [self.mainTable cellForRowAtIndexPath:index][email protected]""; 
    [self.mainTable cellForRowAtIndexPath:indexPath].detailTextLabel.text [email protected]"\U0001F44D"; 

return indexPath; 
} 

回答

2

不要直接改變細胞內的任何值那樣。更改模型(底層數據),然後在選擇發生後(即在runloop完成之後),在表上調用reloadData,以便表通過在平常中調用cellForRowAtIndexPath:來獲取正確的新值辦法。

+0

其實最好還是重裝只有「髒」索引路徑,而不是整個表的 – kambala

+0

@kambala嗯,你可以調用'reloadRowsAtIndexPaths:withRowAnimation:',但如果你不需要這樣做的動畫,因爲即使'reloadData'只爲可見單元重新加載數據,而其中的數據很少,另一方面,reloadRows必須重新計算表格佈局爲'reloadData'。 – matt

-1

您應該使用的,而不是WillSelectRowAtIndexPath didSelectRowAtIndexPath方法

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath  *)indexPath 
{ 

    NSIndexPath *index = [NSIndexPath indexPathForRow:self.selectedCalcMethod inSection:0]; // index of previously selected cell 

    [self.mainTable cellForRowAtIndexPath:index][email protected]""; 
    [self.mainTable cellForRowAtIndexPath:indexPath].detailTextLabel.text [email protected]"\U0001F44D"; 

    return indexPath; 
} 
相關問題