开发者

NSKeyedUnarchiver + UITableViewController not functioning correctly

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.

Whe开发者_JAVA百科n 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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜