2010-01-03 34 views
1

我正在使用ABPersonViewController並在「Info」視圖上添加標籤。 事情是: 當我點擊「編輯」按鈕,因爲:personController.allowsEditing = YES; 我的觀點去「編輯視圖」和我的標籤仍然存在(不像我計劃) 我想弄清楚,如果我可以「通知」,當用戶按下「編輯」按鈕,所以我可以刪除我的標籤從當前視圖進入「Edity View」之前ABPersonViewController - 從「編輯」按鈕回調 - 目標C

我在考慮的唯一選擇是在ABPersonViewController中禁用編輯並創建自己的「編輯」按鈕,然後我將嘗試並執行地址簿「編輯」按鈕的相同行爲...

當按下「編輯」按鈕時是否有回調選項?並仍然保持ABPersonViewController的相同行爲?

也許有知道哪個查看我在ABPersonViewController(標籤或財產以後...?),所以我可以刪除標籤時,我沒有對「信息」視圖的方式

由於

伊泰

+0

什麼編程/腳本語言?請編輯您的問題並相應地更新標籤。 – BalusC 2010-01-03 22:47:27

+0

會做。 謝謝! – Itay 2010-01-04 09:26:56

回答

2

只是想出了一個稍微哈克尋找的方法是按下編輯時得到通知。

創建ABPersonViewController一個子類,並附上自己的自定義動作的編輯按鈕:在初始化爲您的視圖控制器:

-(void)viewDidAppear:(BOOL)animated{ 

    [self.navigationItem.rightBarButtonItem setTarget:self]; 
    [self.navigationItem.rightBarButtonItem setAction:@selector(editPressed)]; 

} 

我找不到比一個更好的參考編輯按鈕:self.navigationItem.rightBarButtonItem

然後創建editPressed行動:

-(void)editPressed{ 

    [super setEditing:!super.editing]; 

    if(self.editing){ 

     NSLog(@"Editing"); 

     //Insert code to put your custom view in edit mode 

    }else{ 

     NSLog(@"Not editing"); 

     //Insert code to take your custom view out of edit mode 

    } 
} 

調用01是很重要的,因爲這會使UIPersonViewController進入和退出編輯模式(定義您的自定義操作會覆蓋默認操作)。它還會正確更新視圖控制器的'editing'屬性,以便'self.editing'提供正確的值。

+0

按「完成」(righttabbarbutton)導致這個解決方案崩潰..任何意見? – AKG 2012-03-19 22:07:45

5

或者,您可以繼承並覆蓋setEditing:animated。這個setter被調用EditDone,但不是Cancel,並且仍然需要回調。下面的例子在編輯記錄時隱藏工具欄,並在完成時恢復它。

// Override setter to show/hide toolbar 
- (void)setEditing:(BOOL)editing animated:(BOOL)animated { 
    [super setEditing:editing animated:animated]; 
    self.navigationController.toolbarHidden = editing; 
    if (editing) { 
     [self.navigationItem.leftBarButtonItem setTarget:self]; 
     [self.navigationItem.leftBarButtonItem setAction:@selector(cancel)]; 
    } 
} 

// Cancel button callback (does not invoke setEditing:animated) 
- (void)cancel { 
    [self setEditing:NO animated:YES]; 
} 
+0

Apple的當前不允許繼承ABPersonViewController的子類。 – 2014-04-22 15:18:45