NSKeyedUnarchiver + UITableViewController 无法正常工作

发布于 2024-09-30 20:42:10 字数 814 浏览 1 评论 0原文

我正在尝试使用 NSKeyedArchiver 来存储 UITabBarController 的状态。选项卡内部是包含 UITableViewController 的 UINavigationController。

归档工作似乎没有任何问题。

取消存档时,我的 UITableViewController 遇到了奇怪的问题。 initWithCoder: 被正确调用,我在里面做的第一件事就是调用 [super initWithCoder:]

tableView 似乎已正确重新创建,并且已经设置了委托和 dataSource 属性。如果我的 initWithCoder: 除了调用 super 并返回 self 之外什么都不做,那么我的表视图最终会变成空,并且不会调用我的委托方法。如果我连接 self.tableView 的 delegate 和 dataSource 属性,我会正确地看到我的内容,但是在选择时不会调用 didSelectRowAtIndexPath,并且在一种情况下,我无法滚动,直到重新加载 tableView 为止。

如果在 initWithCoder: 我创建一个新的 UITableView 一切正常,但我不认为我应该需要这样做。

我是否在尝试这样做时做了一些不应该做的事情,或者我是否遗漏了一些明显需要添加才能使事情正常工作的东西?

更新:在我的控制器内设置self.tableView = [decoderdecodeObjectForKey:@"tableView"]似乎解决了滚动/选择问题,但生成的tableView始终是UITableViewStylePlain并且由于属性已经设置,所以似乎仍然是错误的做法。

I am attempting to use NSKeyedArchiver to store the state of my UITabBarController. Inside the tabs are UINavigationControllers which contain UITableViewControllers.

The archiving appears to work without any problem.

When unarchiving I am running into strange problems with my UITableViewControllers. initWithCoder: is called correctly, and the first thing I am doing inside there is calling [super initWithCoder:]

The tableView appears to be correctly recreated, and has a delegate and dataSource property already set. If my initWithCoder: does nothing but call super and return self then my table view ends up empty and my delegate methods are not called. If I hookup the delegate and dataSource properties of self.tableView I see my content correctly, but didSelectRowAtIndexPath is not called upon selecting, and in one instance I am unable to scroll until the tableView is reloaded.

If in initWithCoder: I create a new UITableView everything works but I don't believe I should need to do this.

Am I doing something I shouldn't be in attempting this, or am I missing something obvious that I need to add to get things working correctly?

Update: setting self.tableView = [decoder decodeObjectForKey:@"tableView"] inside my controller seems to solve the scroll/select problem, but the resulting tableView is always UITableViewStylePlain and still seems like the wrong thing to do as the property is already set.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

2024-10-07 20:42:10

你的设计模式肯定不寻常。通常,您不会尝试归档表视图,而只会尝试归档用于创建它的数据。然后,当您再次需要表视图时,您可以使用最初创建表视图时使用的相同代码,根据这些数据重新创建它。

Your design pattern is certainly unusual. Normally, you wouldn't try to archive the table view, just the data used to create it. Then when you need the table view again, you would recreate it from those data, using the same code you used to create it in the first place.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文