我有关于重新加载视图的问题.
我在我的应用程序中使用tabbar.当我按下主页按钮,我的应用程序在后台.现在我的问题是从现在开始.我希望每次显示第一个标签时.所以,每次我获得第一个标签栏的视图.但是当我得到第一个tabbar的视图时,我viewDidAppear()在AppDelegate中调用了第一个tabar的viewController,如下所示:
- (void)applicationDidBecomeActive:(UIApplication *)application
{
self.tabBarController.selectedViewController=[self.tabBarController.viewControllers objectAtIndex:0];
[navigationController1 popToRootViewControllerAnimated:YES];
[navigationController2 popToRootViewControllerAnimated:YES];
[navigationController3 popToRootViewControllerAnimated:YES];
[navigationController4 popToRootViewControllerAnimated:YES];
[navigationController5 popToRootViewControllerAnimated:YES];
simpleTableViewController *s = [[simpleTableViewController alloc]initWithNibName:@"simpleTableViewController" bundle:nil];
[s viewDidAppear:YES];
}
Run Code Online (Sandbox Code Playgroud)
因此,viewDidAppear()调用并加载数据并打印日志.但视图不会重新加载或刷新.表示tableview没有任何影响.从服务器加载的数据显示在tableview中.
我使用以下代码进行重新加载或刷新视图:
[self.view setNeedsLayout];
[self.view setNeedsDisplay];
[tabledata reloadData];
Run Code Online (Sandbox Code Playgroud)
但它没有受到影响.
提前致谢.
Ian*_*n L 19
当你打电话时:
simpleTableViewController *s = [[simpleTableViewController alloc]initWithNibName:@"simpleTableViewController" bundle:nil];
[s viewDidAppear:YES];
Run Code Online (Sandbox Code Playgroud)
您只是创建该视图控制器的新实例并尝试让它刷新它的数据.不是已经在导航堆栈中的视图控制器.
我建议您添加您simpleTableViewController作为"应用程序确实变为活动"或"将进入前景"通知的观察者.例如:
- (void)viewDidLoad {
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationWillEnterForeground:) name:UIApplicationWillEnterForegroundNotification object:nil];
}
Run Code Online (Sandbox Code Playgroud)
然后在通知处理程序中,您可以重新加载数据:
- (void)applicationWillEnterForeground:(NSNotification *)notification {
[self reloadDataFromWeb];
[self.tableView reloadData];
}
Run Code Online (Sandbox Code Playgroud)
不要忘记删除观察者中simpleTableViewController的dealloc方法.
| 归档时间: |
|
| 查看次数: |
6868 次 |
| 最近记录: |