[英]How to call a method in another view when controller is dismissed
基本上,我遇到的問題是我無法從另一個名為Table的視圖中調用主視圖控制器(稱為Recorder)中的方法。
當用戶單擊按鈕時,表視圖從Recorder作為Modalview控制器(presentmodalViewController)加載。 表格視圖允許我的用戶從設置1更改為設置2,並具有完成按鈕(調用dismissmodalviewcontroller),並將用戶返回到主視圖(記錄器)。
我想要的是在“表視圖”上單擊“完成”按鈕時在Recorder中調用方法。 此方法稱為Changeview並更改設置。 我目前無法正確調用此方法。
我當前的代碼是:
changeView方法
- (void)changeView
{
[levelsView changeView];
}
TableViewController接口文件
RecorderViewController*recorderViewController;
@property (nonatomic, retain) RecorderViewController *recorderViewController;
TableViewController實現文件
@synthesize recorderViewController;
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
[recorderViewController changeView];
}
按下“完成”按鈕時調用的方法
- (IBAction) Switch: (id) sender {
[self dismissModalViewControllerAnimated:YES];
}
當前代碼不會給我任何錯誤,但也不會更改設置。 我也嘗試過設置沒有運氣的通知。 有什么見解嗎?
在初始化tableViewController時是否設置了recorderViewController的值(即,是否在Recorder類中設置tableViewController.recorderViewController = self
)? 如果不是,則您對[recorderViewController changeView]
調用[recorderViewController changeView]
消息發送到[recorderViewController changeView]
不會崩潰,但也不會執行任何操作。
順便說一句,將TableViewController的引用傳遞給RecorderViewController可能不是兩個控制器進行通信的最佳方式:您可能要考慮使用NSNotificationCenter ,或者傳遞模型對象並使用鍵值觀察 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.