强制重新加载 UITableView - Objective-C
我有一个 tabBar 应用程序。有2个UIViewController A和B。UIViewController B有UITableView。我从 B UIViewController 调用 A UIViewController 中的方法: [b someMethod:someObject];
这是代码:
-(void) someMethod:someObject
{
[tableViewDataArray addObject: someObject];
[tableView reloadData];
}
但是 UITableView 不会重新加载,直到我将 UIViewController 切换到 B;如何在不切换的情况下重新加载它?如果这可能的话
I have a tabBar application. There are 2 UIViewControllers A and B. UIViewController B has UITableView. I call method in A UIViewController from B UIViewController: [b someMethod:someObject];
Here is code:
-(void) someMethod:someObject
{
[tableViewDataArray addObject: someObject];
[tableView reloadData];
}
But UITableView doesn't reload until I switch UIViewController to B; How to reload it without switching? If this possible
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
最好的解决方案是在工具栏上放置一个用于添加和刷新的按钮,并创建一个名为
add()
的函数并将其连接到该按钮。在里面你做的:我遇到了类似的问题,这实际上有效,这应该有所帮助:如何在我查看时重新加载 UITableView
your best solution is to put a button on the toolbar for adding and refreshing and make a function called
add()
and connect it to the button. and inside there you do :I was having a similar issue and this actually worked, this should help : How to Reload a UITableView While I am Looking at It
UITabBarController
在实际需要之前不会加载所有选项卡的视图,因此在切换到之前,您的表格视图可能根本不存在(即nil
)包含它的选项卡。虽然您可以通过访问视图控制器的
view
属性来强制视图控制器加载其视图层次结构,但我不推荐这样做。无论如何,重新加载不可见的表视图有什么意义?UITabBarController
doesn't load all its tabs' views until they are actually needed, so your table view probably doesn't even exist (i.e. isnil
) before you switch to the tab that contains it.While you could force the view controller to load its view hierarchy by accessing its
view
property, I wouldn't recommend it. What's the point of reloading an invisible table view anyway?