我是iOS编程的新手,现在有问题。
有一个登录屏幕,用于[self presentViewController:loginview animated:YES completion:nil];
在MasterViewController中将其显示出来。
现在我想在之后调用一个方法(重载数据) [self dismissViewControllerAnimated:YES completion:nil]
这是我的代码:
[self dismissViewControllerAnimated:YES completion:^ {
[self getPostData]; // Reload Data
[self.tableView reloadData]; // Reload Data
}];
但它不起作用。
(重载方法在MasterViewController中)
有人可以帮助我吗?
您可以使用它NSNotificationCenter
来解决您的问题。
在您的MasterViewController
viewDidLoad中定义一个NSNotification,如下所示
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(closeModal:) name:@"CloseModal" object:nil];
然后定义方法如下
-(void)closeModal:(NSNotification *)notification{
UIViewController *controller=(UIViewController *)notification.object;
[controller dismissViewControllerAnimated:YES completion:^ {
[self getPostData]; // Reload Data
[self.tableView reloadData]; // Reload Data
}];
}
最后,从您实际尝试解散您的控制器的其他控制器使用以下代码
[[NSNotificationCenter defaultCenter] postNotificationName:@"CloseModal" object:self];
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句