UIViewController to find out if it was clicked or popped up?

I have a basic UITableView, when a cell is clicked, it goes to another UITableView, and when the cell is clicked there, it goes to the DetailView of that cell.

I want the middle UITableView to behave differently depending on whether the detail window was displayed or the UITableView itself. If the view appeared from the main table, I want to scroll up, if it is displayed after the DetailView has appeared, I want it to remain in the same position.

Any suggestions?

+5
source share
3 answers

scrollToTop DetailViewController , .

- :

if (!detailViewController) {
    detailViewController = [[DetailViewController alloc] initWithNibName:nil bundle:nil];
}
[self.navigationController pushViewController:detailViewController animated:YES];
[detailViewController scrollToTop];
// or use the tableView directly: 
// [detailViewController.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] atScrollPosition:UITableViewScrollPositionTop animated:YES];
+2

, UINavigationController:

- (void)viewWillDisappear:(BOOL)animated
{
    if ([self.navigationController.topViewController isEqual:(UITableViewController *)tvcDetailView]) {
        // Detail view has been pushed onto the UINavigationController stack
    }
    else {
        // Middle view has been popped from the UINavigationController stack
    }
}
+1

BOOL @property UIViewController wasPushed - , UIViewController 1, , nav, loadView, viewDidLoad, viewWill/DidAppear.

Once you use it, return it to FALSE or NO (or something else), and when you return to it because you have lowered your 3rd controller, you will have it as FALSE / NO to your methods loadView, viewDidLoadetc.

0
source

All Articles