2013-03-18 86 views
0

我从这个例子定制刷卡识别类: How to detect a swipe-to-delete gesture in a customized UITableviewCell?进入编辑模式,单列/细胞

- (void)cellSwiped:(UIGestureRecognizer *)gestureRecognizer { 
    if (gestureRecognizer.state == UIGestureRecognizerStateEnded) { 
     UITableViewCell *cell = (UITableViewCell *)gestureRecognizer.view; 
     NSIndexPath* indexPath = [self.tableView indexPathForCell:cell]; 
    } 
} 

现在我想选择单行在indexPath并启用编辑模式吧,有人能告诉我如何做到这一点吗?

回答

2

缓存你想要的地方的行,并在你的实施- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath只是你想要编辑的行的返回YES。然后通过发送[tableView setEditing:YES animated:YES];进入编辑模式。

+0

我明白你想说什么,但我对iOS编程还很陌生,我不完全明白要做什么。我做了这样的事情,似乎没有工作。 if([notifTable cellForRowAtIndexPath:indexPath]){[notifTable cellForRowAtIndexPath:indexPath] setEditing:YES animated:YES]; 返回YES; – user2180859 2013-03-18 04:17:33

0

你可以在你的类中的变量是NSIndexPath *index则有

-(BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath { 
    return indexPath == self.index; 
} 

并设置索引任何你想要的细胞能够编辑,然后调用tableView setEditing:YES animated:YES/NO,每当你想编辑细胞。

0

尝试这样,

在你的tableView didSelectRowAtIndex委托方法调用editingStyleForRowAtIndexPath方法,

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
[yourTableView.delegate tableView:tableView editingStyleForRowAtIndexPath:indexPath]; 
} 

editingStyleForRowAtIndexPath方法,

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath { 


    return UITableViewCellEditingStyleDelete; 

    } 


- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { 



}