调用[tableView reloadData];在从modalViewController的viewController上 [英] Call [tableView reloadData]; on a viewController from a modalViewController
问题描述
我有一个modalViewController,它位于带有tableView的viewController的顶部.当用户单击modalViewController上的按钮时,我想使用以下方法在viewController中重新加载tableView:
I have a modalViewController that comes up over the top of a viewController with a tableView. When the user clicks a button on the modalViewController I want to reload the tableView within the viewController with this:
[tableView1 reloadData];
我不想将重载放入viewDidAppear或viewWillAppear方法中,因为当我不需要重载tableView时(即,当用户单击后退按钮以返回tableView时)它们被调用.
I do not want to put the reload in the viewDidAppear or viewWillAppear methods as they get called when i do not need the tableView to reload (i.e. when the user clicks the back button to return to the tableView).
有没有办法做到这一点?
Is there a way to do this?
推荐答案
使用类似于波纹管方法的通知:-
using Notification like bellow Method:-
在yourViewController的ViewdidLoad
方法中创建NSNotificationCenter
Create NSNotificationCenter
at yourViewController's ViewdidLoad
Mehod
- (void)viewDidLoad
{
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(ReloadDataFunction:)
name:@"refresh"
object:nil];
[super viewDidLoad];
}
-(void)ReloadDataFunction:(NSNotification *)notification {
[yourTableView reloadData];
}
现在,您可以从modelViewController BackButton调用此通知,或者您也可以通过调用此刷新通知,例如放置以下代码行:-
Now you can Call this Notification from your modelViewController BackButton or else you want from calling this Refresh notification like putting this line of code:-
[[NSNotificationCenter defaultCenter] postNotificationName:@"refresh" object:self];
注意: postNotificationName:@"refresh"
这是特定通知的键
这篇关于调用[tableView reloadData];在从modalViewController的viewController上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!