如何重新加载 xib 制作的表中的数据
[myTable reloadData] 不起作用,[myTable deselectRowAtIndexPath:indexPathAnimated:YES] 也不起作用;
我之前对 UITableViewController 进行了子类化,这两个函数都在其中工作。然后我将我的类更改为带有委托的 UIViewController 子类,以便我可以使用 xib。从那时起这些功能就停止工作了。
我已将其设置为通过单击按钮来触发 reloadData。多次运行调试器表明表方法甚至没有被 reloadData 触发,尽管表一开始加载得很好(在单击按钮之前)。委托源和委托都设置为文件的所有者,所以这一切都很好。
太感谢了。
[myTable reloadData] isn't working nor is [myTable deselectRowAtIndexPath:indexPath animated:YES];
I previously subclassed UITableViewController, where both these functions worked. I then changed my class to subclass UIViewController with delegates so I can use a xib. Since then these functions stopped working.
I have it set up so that reloadData is triggered by a button click. Running the debugger many times showed that the table methods aren't even being triggered by reloadData, though the table loads fine to begin with (before clicking the button). Delegate source and delegate are set to File's Owner, so that's all fine.
Thank you so much.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我的猜测是您没有为 myTable 设置插座。这可以解释为什么数据源和委托可以工作,但不能调用重新加载数据。
假设这是问题所在,您需要在 @interface:
和实例变量
UITableView *myTable
中添加以下内容。然后您的实现中需要@synthesize myTable;
。然后,您需要使用界面生成器通过从 File's Owner > myTable 条目中拖动来将表视图分配给此插座。连接选项卡到布局中的表视图。
假设这就是问题所在,您现在可以在表视图上调用诸如 reloadData 之类的方法。
My guess is that you don't have an outlet set to myTable. That would explain why datasource and delegate work, but not calls to reload data.
Assuming this is the issue you need the following in your @interface:
and an instance variable
UITableView *myTable
. Then you need@synthesize myTable;
in your implementation.Then you need to use interface builder to assign your table view to this outlet by dragging from the myTable entry in File's Owner > Connections tab to your table view in the layout.
Assuming this was the problem , you will now be able to call methods such as reloadData on your table view.