作者ObjectiveD (Objective-D)
看板MacDev
标题[问题] 移动 TableView Cell 画面更新问题
时间Wed Sep 25 12:55:18 2013
因为客户的需求,移动编辑TableView cell并没有增加 button 在画面上,
而是使用 UILongPressGestureRecognizer 的手势加在各个 cell 上。
移动时会实作
- (void)tableView:(UITableView *)tableView
moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath
toIndexPath:(NSIndexPath *)destinationIndexPath {
// Data source 资料互换....
// ....
// 结束後
[tableView setEditing:NO animated:YES]; // *1
}
在这 delegate method 执行 结束编辑状态,
当有跨越 tableview 上看不见的 cell (如从最上方 index 0,拖到最下方 index 49),
结束移动的 cell 右方的 accessoryView 无法从编辑状态的 icon 恢复成箭头 icon。
我想是不是不适合在这 delegate method 下 setEditing:animated:?
我目前想到的解法有两种,但不确定会有什麽影响。
1. 在 *1 後面补上 [tableView reload];
缺点:icon 转换的动画,因为 tableView reload 的刷新,反而看不出效果。
2. 利用 delay 的方式
- (void)endMovingCell {
[myTableView setEditing:NO animated:YES];
}
用这行取代上面 *1
[self performSelector:@selector(endMovingCell)
withObject:nil
afterDelay:0.01];
PS: 秒数我设0还是正常,挺诡异...
目前是用2的解法。
我的疑问是,这样会有什麽潜在问题吗?
翻了一下 Apple文件,没找到跟 didMoveRowAtIndexPath 相关的 delegate method...
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 118.163.16.106