[英]Closing dismissViewController doesn't fire the viewWillAppear
我有一個視圖,可以打開模態順序視圖。
我使用以下代碼打開此視圖:
- (IBAction)openInfopage:(UIButton *)sender;
{
[self performSegueWithIdentifier:@"Infopage" sender:self.view];
}
我通過以下方式關閉此視圖:
- (IBAction)closeView:(id)sender {
// old version:
//[self dismissViewControllerAnimated:YES completion:nil];
// my new version:
[self.presentingViewController dismissViewControllerAnimated:YES completion:nil];
}
關閉模態后,我想用模態視圖生成的新數據更新視圖。
我使用[self.tableView reloadData];
更新,但是我可以在哪里放置此代碼,因此它將開始?
我嘗試使用viewWillAppear,但是在關閉模式視圖時不會調用此方法。
我總是將這些內容放入委托協議中。 因此,只需將其插入您的modal-viewcontroller.h:
@protocol MyDelegateProtocol <NSObject>
@optional
-(void)modalFinished;
@end
@interface ViewController : UIViewController
@property (nonatomic, weak) id <MyDelegateProtocol> delegate;
@end
並在.m中調用:
if(_delegate) [_delegate modalFinished];
完成后。 在呈現的ViewController中,您必須做到這一點:
<MyDelegateProtocol>
@implementation行之后。 並實現委托方法-(void)modalFinished。 用這種方法可以刷新。 當然,還要在呈現視圖控制器中將modal-viewcontroller的proxy屬性設置為self。
編輯:
MyViewController mvc = ...;
MyViewController.delegate = self;
[self presentViewController:...];
如果您通過segue出席:
在prepareForSegue中:
MyViewController *mvc = segue.destinationViewController;
mvc.delegate = self;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.