作者peliuya (Unknown)
看板MacDev
标题Re: [问题] reloadRowsAtIndexPath exception
时间Mon Nov 4 15:43:39 2013
※ 引述《uranusjr (←这人是超级笨蛋)》之铭言:
: 当 textFieldShouldEndEditing 被呼叫时, text field 还没有结束编辑
: 这时候你还不能对包含它的 cell 进行 reload (正确来说应该是不能 remove)
: 不然程式就...嗯, 失去了 consistency
: 解决方法是不要在 textFieldShouldEndEditing: 直接呼叫 reload
: 而是要在它「结束之後」排定一个 reload 事件
: 最简单的解法(之一)是用 GCD 塞一个 async call
: http://stackoverflow.com/questions/13907335/
感谢解说
我把code改成
- (BOOL) textFieldShouldEndEditing:(UITextField *)textField
{
NSIndexPath *AlertPath = [NSIndexPath indexPathForRow:1 inSection:0];
NSArray *myArray = [NSArray arrayWithObjects:AlertThresholdPath, nil];
dispatch_async(dispatch_get_main_queue(), ^{
[self.functionTable reloadRowsAtIndexPaths:myArray
withRowAnimation:UITableViewRowAnimationAutomatic];
});
return YES;
}
可是出现了资料不同步的问题
Initail textField text : 50
输入51 return後
在 reload时, 读取的textField text 仍为50
再输入52 return後 , reload 读取为51, 会有延迟一次编辑的状况
请问该怎麽处理呢?
谢谢
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 60.251.44.30
1F:推 guninia:有在didEndEditing这个方法里面试过吗? 11/04 16:01
2F:→ peliuya:试过在didEndEditing才reload 结果是一样的 11/04 16:06
3F:推 tentenlee:设delay0.1 0.2秒後在reload 11/04 16:49
4F:→ peliuya:仍然不行 问题应该是在另一段code 感谢您的指导 11/04 17:21