简体   繁体   English

如何从委托访问UITableView?

[英]How to access UITableView from delegate?

When I dismiss a modal, I'm overriding viewWillAppear in order to make the table view in the view reload. 当我解雇一个模态时,我重写了viewWillAppear ,以便在视图中重新加载表视图。 The problem is that I don't have any pointer to the table view to call it to refresh. 问题是我没有任何指向表视图的指针来调用它来刷新。 I've considered awkward solution such as storing it in a pointer when the tableview first loads and calls the UIViewController (the delegate) for each row, but it seems that there hast to be a pointer to it somewhere. 我考虑过尴尬的解决方案,例如在tableview首次加载时将其存储在指针中,并为每一行调用UIViewController (委托),但似乎有一个指向它的指针。 Does anyone know how to get it? 有谁知道如何得到它?

It's very common for a viewController with a UITableView in it's view hierarchy (even as the root, in the case of a UITableViewController ) to keep a weak pointer to the UITableView for just this kind of thing. 这是很常见的一个viewControllerUITableView在它的视图层次结构(甚至为根,以的情况下UITableViewController ),以保持一个弱指针UITableView只是这种事情。

If the UITableView is built in storyboard/xib , set it up as an IBOutlet , otherwise, build the UITableView in code, add it as a subview and assign a pointer to self.tableView . 如果UITableView是在storyboard/xib ,则将其设置为IBOutlet ,否则,在代码中构建UITableView ,将其添加为子视图并指定指向self.tableView的指针。

viewWillAppear is a perfectly sensible place to say [self.tableView reloadData] viewWillAppear是一个非常明智的地方[self.tableView reloadData]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM