好吧,爲UITableViewController的標準模板代碼,我一直在使用cellForRowAtIndexPath:
設置我的UITableViewCells基於數據源。cellForRowAtIndexPath和單元格配置
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
//cell setup
cell.textLabel.text = @"Initial Data!";
return cell;
}
但是,這突然讓我覺得這是一個有問題的做法。舉例來說,可以說,我想這樣做
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
//some processing or data update is done here
//now I want to update the cell
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
cell.textLabel.text = @"New Data";
}
看起來這是浪費的代碼,因爲檢索的細胞更新,導致它被更新在的cellForRowAtIndexPath代碼中的第二次。
所以我應該把配置小區別的地方,把它一些其他的方式,或者我應該以更聰明的方式寫在cellForRowAtIndexPath
配置,以便給它一個簡單的通話將更新UI withou
我認爲你的問題被切斷了。 – jakev 2011-02-18 21:44:44