2013-03-18 87 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 { 



}