[英]Replace action of swipe to delete by clicking on a button
我有一個帶有標簽的tableview和每個單元格上的兩個按鈕。 目前我有這個代碼可以輕掃以刪除。
- (void) tableView: (UITableView *) tableView commitEditingStyle: (UITableViewCellEditingStyle) editingStyle forRowAtIndexPath: (NSIndexPath *) indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
[appointments removeObjectAtIndex: indexPath.row]; // manipulate your data structure.
[tableView deleteRowsAtIndexPaths: [NSArray arrayWithObject: indexPath]
withRowAnimation: UITableViewRowAnimationFade];
NSLog(@"row deleted"); // Do whatever other UI updating you need to do.
}
}
我滑動時會執行此代碼。 但是我希望它在按下按鈕時執行。 該按鈕與以下IBAction鏈接。
- (IBAction)deleteRow:(id)sender {
//Delete row
}
要記住一件事。 我希望刪除按鈕像滑動刪除時一樣滑動。
有誰能夠幫助我?
如果您的按鈕位於單元格中,則可以將其tag屬性設置為indexPath.row值,並為其指定deleteRow:(id)sender方法,通過-(void)addTarget:(id)target action:(SEL)action forControlEvents:(UIControlEvents)controlEvents
為了讓按鈕滑動,您可能需要實現panGestureRecognizer。 我可能錯了,但這個想法應該是檢測觸摸位置和滑動按鈕(在滑動時設置框架)。 如果您打算通過滑動按鈕刪除,則可能需要禁用在桌面上滑動才能刪除。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.