views:

60

answers:

2

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.

Here's a rough image, because its hard to explain in writing:

http://96.248.81.29:83/misc/PushPopSituation.png (Thats a fixed IP, its not going anywhere)

If anyone knows how I could do something like this, it would be a great help to me.

+1  A: 

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.

warrenm
I'm going to use the UINavigation Controller Delegate, and when it is about to pop the view, I will scroll the tableview accordingly, highlight the cell, and then use the [tableView deselectRowAtIndexPath:indexPath animated:YES]; method to make it look like i popped it right. I'll try it and report back on how it goes
ckrames1234
A: 

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];

I really wanted to subclass UITableView and UINavigation Controller, but it is forbidden by Apple... Thats what makes Android the ideal developer platform: open-source.

I hope you guys understand what I was trying to do by looking at the code. This is only a half-assed solution, buts it's what had to be done.

ckrames1234