Re: [問題] reloadRowsAtIndexPath exception
※ 引述《peliuya (Unknown)》之銘言:
: ※ 引述《uranusjr (←這人是超級笨蛋)》之銘言:
: : 當 textFieldShouldEndEditing 被呼叫時, text field 還沒有結束編輯
: : 這時候你還不能對包含它的 cell 進行 reload (正確來說應該是不能 remove)
: : 不然程式就...嗯, 失去了 consistency
: : 解決方法是不要在 textFieldShouldEndEditing: 直接呼叫 reload
: : 而是要在它「結束之後」排定一個 reload 事件
: : 最簡單的解法(之一)是用 GCD 塞一個 async call
: : http://stackoverflow.com/questions/13907335/
問題可能是出在 cellForRowAtIndexPath 內, 才有資料不同步的情況
cellForRowAtIndexPath
{
AlertThresholdCell *AlertCell= (AlertThresholdCell *)
[tableView dequeueReusableCellWithIdentifier:@"AlertCell"];
if (AlertCell == nil)
{
NSArray *nibs;
nibs = [[NSBundle mainBundle]loadNibNamed:@"AlertThreshold"
owner:self options:nil];
AlertCell = [nibs objectAtIndex:0];
}
AlertCell.delegate = self;
NSLog(@"%@", AlertCell.textField);
return AlertCell;
}
textFieldShouldEndEditing
{
NSIndexPath *AlertThresholdPath;
AlertThresholdPath = [NSIndexPath indexPathForRow:1 inSection:0];
NSArray *myArray = [NSArray arrayWithObjects:AlertThresholdPath, nil];
dispatch_async(dispatch_get_main_queue(), ^{
[self.functionTable reloadRowsAtIndexPaths:myArray
withRowAnimation:UITableViewRowAnimationAutomatic];
NSLog(@"%@", textField);
return YES;
}
這兩處印出的textField是不同的,
直到下次編輯結束 cellForRowAtIndexPath 中,
AlertCell才會拿到上次編輯的textField
請問我該怎麼保持資料的一致性呢?
我在cellForRowAtIndexPath 是否撰寫得有問題呢?
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 60.251.44.30
→
11/04 22:52, , 1F
11/04 22:52, 1F
→
11/04 22:52, , 2F
11/04 22:52, 2F
→
11/04 22:52, , 3F
11/04 22:52, 3F
推
11/04 22:57, , 4F
11/04 22:57, 4F
→
11/04 22:59, , 5F
11/04 22:59, 5F
→
11/04 23:03, , 6F
11/04 23:03, 6F
→
11/04 23:04, , 7F
11/04 23:04, 7F
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 4 之 4 篇):
MacDev 近期熱門文章
PTT數位生活區 即時熱門文章