2011-05-13 74 views
1

我想,当用户扫描到一个UITableViewCell的权利做一些东西,所以我用问题与刷一个UITableViewCell

- (void)tableView:(UITableView *)tableView willBeginEditingRowAtIndexPath:(NSIndexPath *)indexPath 

但是我试图向右滑动,这并没有得到被调用,这是为什么?我所有的UITableView委托都被调用。

我也有这个在我的代码:

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    return YES; 
} 


// Override to support editing the table view. 
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath 
{ 

} 

所有我想要做的是,当刷卡发生

+0

这很奇怪,因为我只是试过同样的事情,当我刷卡时它会调用它。我确定你有,但是你说你已经建立了你的tableView委托和dataSource到self,并且把tableView委托和dataSource协议放在头文件中?没关系的是,我相信麦克沃斯撞上了它的鼻子 – justin 2011-05-13 18:30:00

+0

它可能只是设置数据源而不是代表。 – 2011-05-13 19:19:13

+0

我已经设置了代理和数据源 – aherlambang 2011-05-13 20:23:52

回答

0

尝试增加这个方法将你的tableView委托方法:

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { 
     if (editingStyle == UITableViewCellEditingStyleDelete) { 
      // Delete the row from the data source. 
      [self.listTableView beginUpdates]; 
... 

我假设,因为你的其他委托方法被调用,你包括在您的.h文件中@interface行?如果使用IB,你是否右键点击tableview并连接委托和数据源?

0

设置表视图的属性添加一个子视图

tableView.editing = YES; 
+0

我已经在viewDidLoad – aherlambang 2011-05-13 18:19:12

+0

里面做过IBOutlet是否正确连接?做正确的以及左滑动...并检查它是否正常工作... – 2011-05-13 18:21:25

1

你有tableView:commitEditingStyle:forRowAtIndexPath:方法吗?

引述苹果:

Note: A swipe motion across a cell does not cause the display of a Delete button 
unless the table view's data source implements the 
tableView:commitEditingStyle:forRowAtIndexPath: method. 

而且,删除该方法在我的项目也使willBeginEditing不被调用。

+0

你把NSLog的canEdit和willBeginEdit?如果以编程方式进入编辑模式(setEditing:animated)会发生什么?你是否实现了tableView:editingStyleForRowAtIndexPath:?如果是这样,它说什么,它是怎么叫的? – mackworth 2011-05-13 19:14:17

1
// You missed this? 
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath { 
    return YES; 
} 


- (UITableViewCellEditingStyle)tableView:(UITableView *)theTableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath { 
    return UITableViewCellEditingStyleDelete; 
} 


- (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath { 
    return @"Remove"; 
} 


- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { 
    if (editingStyle == UITableViewCellEditingStyleDelete) { 
    [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:YES]; 
    } 
} 

希望有所帮助。

+0

我有这一切 – aherlambang 2011-05-13 18:37:12