UITableViewController 在 popViewControllerAnimated 后不重绘新的单元格文本标签
我有一个问题 UITableViewController 在删除子视图后无法重绘更新的单元格。
这就是发生的事情。更改子视图中的数据后,父视图控制器会重新加载源数据数组并通过 PostNotification 运行[tableView reloadData]。在此触发后,我使用 popViewControllerAnimated 返回到父 UITableViewController (这会将子视图从堆栈中弹出,并显示上一级的控制器)。
但是,我更新的数据没有出现在父视图控制器中!根据调试器的信息,单元格的标签已更新,但可见标签没有改变。但是,如果我滚动轻拂表格,暂时将更新的单元格移出视图,当它重新出现时,标签就会更新!
我还尝试通过 viewWillAppear 调用 [tableView reloadData] 但问题仍然存在。
以下是一些可能有用的附加信息。我有一个如下结构的 3 个视图:
1/ SettingsViewController : UITableViewController
2/ -- UserView : UITableViewController
3/ ---- UserDetailsView : UIViewController <UIActionSheetDelegate>
我从 UserView 内部调用 UserDetailsView,如下所示:
UserDetailsView *userDetailsView = [[UserDetailsView alloc] init];
[self.navigationController pushViewController:userDetailsView animated:YES];
如果我返回到最顶层的控制器 (SettingsViewController),然后加载有问题的控制器 (UserView),则所有内容都会正确绘制。仅当从子视图返回时才会出现此问题。
预先感谢您的建议。
I have a problemetic UITableViewController fails to redraw an updated cell after a child view is removed.
Here's what's happening. After changing data in a child view, the parent view controller reloads the source data array and runs [tableView reloadData] via a PostNotification. After this triggers, I use popViewControllerAnimated to return to the parent UITableViewController (this pops the child view off the stack, and reveals the controller one level up).
However, my updated data does not appear in the parent view controller! According to the debugger, the cell's label has been updated, but the visible label does not change. However, if I scroll-flick the table, momentarily moving the updated cell out of view, when it reappears the label is updated!
I also try calling [tableView reloadData] via viewWillAppear but the issue still persists.
Here is some additional info that may be helpful. I have a 3 views structured like this:
1/ SettingsViewController : UITableViewController
2/ -- UserView : UITableViewController
3/ ---- UserDetailsView : UIViewController <UIActionSheetDelegate>
I am calling UserDetailsView from inside UserView as follows:
UserDetailsView *userDetailsView = [[UserDetailsView alloc] init];
[self.navigationController pushViewController:userDetailsView animated:YES];
If I return to the top-most controller (SettingsViewController) and then load the problematic controller (UserView), everything is drawn correctly. It is only when returning from a child view that this issue occurs.
Thank you in advance for your suggestions.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
经过大约一个小时的配对编码后,终于解决了这个问题。
过了一会儿,我们注意到每当我们发送 reloadData 消息时,tableView 总是 null。
正如您在 Objective C 中所知,空对象毫无怨言地接受任何消息。
事实证明,“某人”(咳咳,抱歉是我)在头文件中定义了这一行。
现在,聪明的 cookie 就会知道,因为我们扩展了 UITaleViewController,所以我们不需要自己创建一个指向 tableView 的指针。实际上,我已经用空对象替换了继承的 tableView 成员。
谜团解开了。希望这对其他人也有帮助! :D
Finally worked this one out after about an hour of paired coding.
After a while We noticed that tableView was always null whenever we sent the reloadData message.
As you may know in Objective C, null objects accept any message without complaint.
It turns out that "someone" (ahem, sorry it was me) had defined this line in the header file.
Now you smart cookies out there will know that because we extend UITaleViewController, we do not need to make a pointer to tableView ourselves. In effect I had replaced the inherited tableView member with a null object.
Mystery solved. Hopefully this helps someone else out there too! :D