在我的應用程序需要能夠跟蹤識別的UITextField來自哪個小區的時候我犯textFieldDidEndEditing:
編輯修改。爲此,我只需在tableview:cellForRowAtIndexPath:
單元格的文本字段上設置標籤屬性即可。一行之後更新的UITableViewCell標籤財產轉移
當單元格移動時,這會導致一些麻煩。例如,如果我將底部單元格移到頂部,請刪除現在位於底部的單元格,然後嘗試編輯剛剛放置在頂部的單元格,我的應用程序將因爲標籤屬性仍然爲8而崩潰(或另一個數字),但是我的數據源中沒有這麼多元素。
我試圖通過更新標籤中tableView:moveRowAtIndexPath:toIndexPath:
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
NSString *siteToMove = [[sites objectAtIndex:[fromIndexPath row]] retain];
[sites removeObjectAtIndex:[fromIndexPath row]];
[sites insertObject:siteToMove atIndex:[toIndexPath row]];
if ([toIndexPath section] == 1) {
[[(BookmarkTextEntryTableViewCell *)[[self tableView] cellForRowAtIndexPath:toIndexPath] textField] setTag:[toIndexPath row]];
}
}
來解決這個問題。然而,這並不工作,因爲(BookmarkTextEntryTableViewCell *)[[self tableView] cellForRowAtIndexPath:toIndexPath]
返回是移動行有之前細胞。