我試圖從它的原始索引中刪除一個單元格,並把它放在tableview
的開頭,我試圖用此代碼做到這一點,但我不能,它崩潰,所以我需要別人的幫助...如何刪除單元格並將其放置在另一個索引中?
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
[cell setSwipeGestureWithView:important color:yellowColor mode:MCSwipeTableViewCellModeSwitch state:MCSwipeTableViewCellState3 completionBlock:^(MCSwipeTableViewCell *cell, MCSwipeTableViewCellState state, MCSwipeTableViewCellMode mode) {
NSIndexPath *myindex = [self.tableview indexPathForCell:cell];
NSIndexPath *newIndexPath = [NSIndexPath indexPathForRow:0 inSection:0];
[self.tableview beginUpdates];
[self.tableview moveRowAtIndexPath:myindex toIndexPath:newIndexPath];
[self.tableview endUpdates];
[self.userdefaults setObject:self.tasks forKey:@"tasks"];
[self.userdefaults synchronize];
}
}
這是崩潰日誌:
'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 2 beyond bounds [0 .. 1]'
謝謝!
你試過 - [UITableView moveRowAtIndexPath:toIndexPath:]? –
要走出一個肢體,並說你不應該刪除並在cellForRowAtIndexPath方法中添加單元格 –
偉大的@RhythmicFistman完美地工作,但這個新的單元格順序不savig,tableview數據是從一個數組(任務)如何我能解決這個問題嗎?我試着添加更新的代碼 –