On the iPad, I've noticed that apps like Mail and WebMD keep rows in the final level of the hierarchy of the "Master" (left) view highlighted when tapped. They also remember this state after rotation; if you select an e-mail in landscape and then rotate to portrait, and click the Inbox button to bring up the Master view popover, the correct item is still highlighted, and the list is scrolled to the correct position. Rotate it back to landscape and it's still correct.
I am working on an iPad app similar to Mail. If I launch my app in landscape, select an item from the list, and rotate my iPad, the Master view seems to lose its state; its table is scrolled to the top and no items are highlighted. Even if the device is then returned back to the landscape orientation the list has still forgotten the last item tapped.
Is there some simple/automati开发者_开发技巧c way to get a Master view in a UISplitViewController
to save its state? I think I can reproduce this behaviour by storing the NSIndexPath
of the last-tapped item and use UITableView
's scrollToRowAtIndexPath:atScrollPosition:animated:
to jump it to the correct place before/after device rotation, but I am hoping that this is already done automatically on the Apple side of things if I flip the right switch.
Turns out it is a "switch" on the Apple side -- specifically, the clearsSelectionOnViewWillAppear
property in UITableViewController
which is set to YES
by default. Setting it to NO
lets it remember its state.
精彩评论