在 UINavigationController 层次结构中刷新 UITableView 的最佳方法是什么
我对 iPhone 开发还很陌生,一直在努力寻找我认为解决这个问题的巧妙方法。
我有一个用户界面,其中记录数据的摘要显示在导航控制器内的表格中。当用户单击一行的附件按钮时,一个新视图将被推送到导航控制器上,显示用户可以在其中编辑相应记录中的数据的视图。完成后,编辑视图将从导航控制器的堆栈中弹出,并且用户返回到表视图。
我的问题是,当用户返回表视图时,表仍然显示编辑记录之前的数据状态。因此,我必须重新加载表数据以显示更改。
在显示之前似乎不可能重新加载表数据,因为调用仅更新显示的记录。显示表格后重新加载它会导致旧数据在用户眼前发生变化,我对此不太满意。
在我看来,这在 iPhone 应用程序中是一件很正常的事情。
谁能建议执行此操作的最佳实践方法?我觉得我失去了一些东西。
干杯 - 史蒂夫。
I'm pretty new to iPhone development and have struggled to find what I consider to be a neat way around this problem.
I have a user interface where a summary of record data is displayed in a table inside a navigation controller. When the user clicks the accessory button for a row, a new view is pushed onto the navigation controller revealing a view where the user can edit the data in the corresponding record. Once done, the editing view is popped from the navigation controller's stack and the user is returned to the table view.
My problem is that when the user returns to the table view, the table still shows the state of the data before the record was edited. I must therefore reload the table data to show the changes.
It doesn't seem possible to reload the table data before it is displayed as the call only updates displayed records. Reloading it after the table has been displayed results in the old data changing before the user's eyes, which I'm not too happy with.
This seems to me like a pretty normal thing to want to do in an iPhone app.
Can anyone please suggest the best practice approach to doing this? I feel like I'm missing something.
Cheers - Steve.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
标准方法一开始听起来可能很麻烦,但对于很多情况来说都是一种有用的模式。
在您的 tableview 类中创建一个方法,例如:
向编辑控制器添加一个属性,例如:
单击附件时设置委托:
编辑完成后,像这样调用您的方法:
您可以创建类似的方法来处理编辑的取消组件,或者执行模式编辑控制器的解除等。如果您愿意,将所有这些都放在协议中被认为更优雅。
The standard approach may sound like a lot of hassle at first, but is a useful pattern for a lot of situations.
In your tableview class create a method like:
Add a property to your edit controller like:
Set the delegate when your accessory is clicked:
And when editing is complete, call your method like so:
You can create similar methods to handle cancel of your edit component, or to carry out dismissing of modal edit controllers, etc. It's considered more classy to put all this in a protocol, if you like.
我将通过以下方式实现此操作:
保存单击的单元格的索引路径。
实现视图控制器的
-[UIViewController viewWillAppear:]
方法,该方法包含UITableView。如果保存的indexPath不为零,则使用以下命令重新加载指定的单元格:-[UITableView reloadRowsAtIndexPaths:withRowAnimation:]
I'd implement this in the following way:
Save indexPath of a clicked cell.
Implement
-[UIViewController viewWillAppear:]
method of the view controller, which contains the UITableView. If saved indexPath is not nil, reload specified cells with:-[UITableView reloadRowsAtIndexPaths:withRowAnimation:]