开发者

UITableView custom popping

开发者 https://www.devze.com 2022-12-22 00:51 出处:网络
Okay, I made an app that has a list of items as a main view, and when you select an item it pushes a detail view controller. In this detail view controller you can switch between items. I want to be a

Okay, I made an app that has a list of items as a main view, and when you select an item it pushes a detail view controller. In this detail view controller you can switch between items. I want to be able to push a view, scroll a few items, and pop the view as if the current item was initially selected.开发者_高级运维 I want to push a view, and then when i pop it, i want it to look like a different view was initially pushed.

Any ideas on how to do this?


Take a look at UITableView's selectRowAtIndexPath:animated:scrollPosition: method. You can call it from within your view controller's viewDidAppear method to achieve the illustrated effect, I believe.

Consider that this is probably not what you really want to do. Leaving a table cell highlighted after a return from a detail view has been condemned by Apple and will be jarring to users unless you have a really good reason for it.


So far, to achieve this effect, I have used this to mask the original UITableViewCell from highlighting.

I have added this in the -(void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated method

[self.tableView selectRowAtIndexPath:selectedRow animated:NO scrollPosition:UITableViewScrollPositionNone];
[self.tableView deselectRowAtIndexPath:selectedRow animated:NO];

Where selectedRow is the Index Path of the original cell selected. I have also added the code below to scoll to and highlight the correct UITableViewCell.

[self.tableView scrollToRowAtIndexPath:tempPath atScrollPosition:UITableViewScrollPositionMiddle animated:NO];
[self.tableView selectRowAtIndexPath:tempPath animated:NO scrollPosition:UITableViewScrollPositionMiddle];
[self.tableView deselectRowAtIndexPath:tempPath animated:YES];
0

精彩评论

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