我想從我向左滑動時刪除所有選定的單元格。從UITableView中刪除選定的單元格
我.m文件
- (IBAction)handleSwipeLeft:(UISwipeGestureRecognizer *)sender{
CGPoint location = [_gestureSwipeLeft locationInView:_tblThingsToDo];
NSIndexPath *swipedIndexPath = [_tblThingsToDo indexPathForRowAtPoint:location];
UITableViewCell *swipedCell = [_tblThingsToDo cellForRowAtIndexPath:swipedIndexPath];
if (swipedCell.selected == NO) {
swipedCell.selected = YES;
}
else{
swipedCell.selected = NO;
}
}
-(void)deleteCurrentobject:(id)sender{
if(self.selectedCells){
[_things removeObjectAtIndex:_indexPath.row];
[self.tblThingsToDo deleteRowsAtIndexPaths:[NSArray arrayWithObject:_indexPath] withRowAnimation:UITableViewRowAnimationFade];
}
}
我希望所有的swipedCell.selected要刪除的調用deleteCurrentObject方法按鈕按下時。我該怎麼做?
添加swipedCell.selected財產KVC下,並設置目標方法作爲KVC方法上下文中的選擇器(即deleteCurrentobject :)。 – Tirth
我該怎麼做?什麼是KVC? – Dridia
KVC意思是鍵值編碼。通過這個文檔https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/KeyValueObserving/Articles/KVOCompliance.html#//apple_ref/doc/uid/20002178-BAJEAIEE – Tirth