簡體   English   中英

使用故事板設置UITableViewController的委托

[英]Setting delegate of a UITableViewController using Storyboards

我正在嘗試使用Storyboards設置UITableViewController的委托。 我遇到的問題是,我要設置的UITableViewController的委托不僅僅是簡單的初始視圖控制器目標。 因此,我決定啟動應用程序后將使用此方法:

- (void)viewDidLoad {
AddListTermsViewController *addListTerms = [self.storyboard instantiateViewControllerWithIdentifier:@"AddListTerms"];
addListTerms.delegate = self;
}

然后,我像這樣設置UITableViewController的Storyboard ID:

在此處輸入圖片說明

但是,當我啟動UITableViewController並記錄委托時,會收到null。 有任何想法嗎? 提前致謝。

編輯

當我像這樣將輸出記錄在初始視圖控制器中時,得到一個肯定的結果:

AddListTermsViewController *addListTerms = (AddListTermsViewController*)[self.storyboard instantiateViewControllerWithIdentifier:@"AddListTerms"];
addListTerms.delegate = self;
NSLog(@"%@", addListTerms.delegate);

但是當我在UITableViewController上記錄輸出時,我再次收到null

我猜你需要將Storyboadcontroller類型轉換為AddListTermsViewController

嘗試這個

  AddListTermsViewController *addListTerms = (AddListTermsViewController*)[self.storyboard instantiateViewControllerWithIdentifier:@"AddListTerms"];

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM