2012-02-05 50 views
3

我有一個UITableView與其中的一些自定義單元格。在這些自定義單元格中,我定義了一個觸發此表的編輯模式的UILongPressGestureRecognizer。所以當有人按住1.5秒時,表格進入編輯模式。觸發器setEditing:動畫:不使用編輯按鈕

UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(startEditMode:)]; 

觸發:

- (void)startEditMode:(UISwipeGestureRecognizer *)recognizer { 

    if (self.allowEdit) { 
     UITableView *table = (UITableView *)self.superview; 
     [table setEditing:YES animated:YES]; 
    } 

} 

但是我想做的是當表進入編輯模式,因爲我需要顯示/隱藏在這種情況下,一些額外的按鈕檢測。但由於某種原因,在我的視圖控制器,這是從未執行:

- (void)setEditing:(BOOL)editing animated:(BOOL)animated { 
    NSLog(@"SET EDITING"); 
    [super setEditing:editing animated:animated]; 
} 

任何建議爲什麼?這只是在使用UINavigationController中默認提供的適當編輯按鈕時才被調用?

或者我該如何檢測UITableView何時進入編輯模式?

回答

4

你正在發送消息(setEditing)到表視圖,你應該發送它到視圖控制器(大概是一個UITableViewController子類?)。然後它會爲您處理桌面視圖。

1

好吧,以防萬一別人走進這個線程有同樣的問題,我會告訴你我是如何解決這個問題的。

在我的自定義UITableViewCell我現在有這樣的方法:

- (void)startEditMode:(UISwipeGestureRecognizer *)recognizer { 

    if (self.allowEdit) { 
     UITableView *table = (UITableView *)self.superview; 
     UITableViewController *control = (UITableViewController *)table.dataSource; 
     [control setEditing:YES animated:YES]; 
    } 

}