Re: [問題] reloadRowsAtIndexPath exception

看板MacDev作者 (Unknown)時間11年前 (2013/11/04 15:43), 編輯推噓2(202)
留言4則, 3人參與, 最新討論串3/4 (看更多)
※ 引述《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

11/04 16:01, , 1F
有在didEndEditing這個方法裡面試過嗎?
11/04 16:01, 1F

11/04 16:06, , 2F
試過在didEndEditing才reload 結果是一樣的
11/04 16:06, 2F

11/04 16:49, , 3F
設delay0.1 0.2秒後在reload
11/04 16:49, 3F

11/04 17:21, , 4F
仍然不行 問題應該是在另一段code 感謝您的指導
11/04 17:21, 4F
文章代碼(AID): #1ITr0kJ8 (MacDev)
文章代碼(AID): #1ITr0kJ8 (MacDev)