Sca*_*tch 6 iphone objective-c uitableview
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
return YES;
}
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{
return UITableViewCellEditingStyleDelete;
}
- (void)tableView:(UITableView *)tableView commitEditingStyle(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{
if(editingStyle == UITableViewCellEditingStyleDelete){
//[theSimpsons removeObjectAtIndex:indexPath.row];
NSString *time = [[arrayList objectAtIndex:indexPath.row] objectForKey:@"TIME"];
NSString *date= [[arrayList objectAtIndex:indexPath.row] objectForKey:@"DATE"];
DBManager *dbm = [[DBManager alloc] init];
[dbm initiallzeDatabase];
[dbm deleteItemAtIndexPath:time :date];
//arrayList = [dbm getParkResults];
//[parkTableView reloadData];
[arrayList removeObjectAtIndex:indexPath.row];
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
}
}
Run Code Online (Sandbox Code Playgroud)
我在我的应用程序中使用了上面的代码.编辑部分工作正常,但事实是,删除按钮仅在我们从单元格从左向右滑动时出现.现在我有一个菜单,可以像Facebook一样从左到右滑动.那么当用户从右向左滑动时,如何确保显示删除按钮.
请不要将代表设置为 UISwipeGestureRecognizer
写下这个viewDidLoad或你发起你的地方UITableView
UISwipeGestureRecognizer *swipeRight = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(callYourMethod:)];
swipeRight.direction = UISwipeGestureRecognizerDirectionRight;
[self.tblView addGestureRecognizer:swipeRight];
Run Code Online (Sandbox Code Playgroud)
无需在下面的方法中写任何东西.
- (void)callYourMethod:(UISwipeGestureRecognizer *)recognizer
{
}
Run Code Online (Sandbox Code Playgroud)
这可能有效。将此代码放入awakeFromNib或init:
UISwipeGestureRecognizer *swipeDelete = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeDelete:)];
[swipeDelete setDirection: UISwipeGestureRecognizerDirectionLeft];
[yourTableView addGestureRecognizer:swipeDelete];
Run Code Online (Sandbox Code Playgroud)
然后handleSwipeDelete组织您的单元格并显示删除按钮。您可能需要处理单元格状态并在向左滑动/向右滑动时更改它。
| 归档时间: |
|
| 查看次数: |
6670 次 |
| 最近记录: |