开发者

Automatically drill down through navigation hierarchy?

开发者 https://www.devze.com 2023-01-28 10:13 出处:网络
I have a navigation-based app that allows the user to drill down through hierarchies. Some of the child hierarchies have only one element in them, e.g.,

I have a navigation-based app that allows the user to drill down through hierarchies. Some of the child hierarchies have only one element in them, e.g.,

TopLevel1----->Level2a
TopLevel2   |->Level2b----->Level3a----->Level4a
            |->Level2c    

Instead of making the user tap 'Level3a', I just want to jump from Level2b to Level4a, but keep the Level3a view in the stack so when the user backtracks, it is visible.

I found some code here to simulate a row tap:

Simulate a Detail Disclosure Button press

When each level is loaded, I check to see if there is only one element in it. If so, I simulate the row tap. This all works initially, and the final view is loaded. But when I start backtracking through the view hierarchy, I get problems (it appears that the skipped view开发者_如何学Gos aren't loaded).

I think what I'm trying to accomplish is fairly simple, so I'm hoping someone on here can point me in the right direction.


You should be able to place a [self.navigationController pushViewController:level4 animated:NO] call in the viewWillAppear method for your level3 view controller. This will automatically push level4 on top of level3.

If it only happens some of the time, level3 can have a property to indicate when this behavior takes place.


I'm not 100% sure that would work, but that's what I would do.

You could directly [self.navigationController pushViewController:level4a animated:NO] and when that's done, set a new array of viewControllers, the navigationController propriety (an array that includes Level3a).

Here is a code sample, in you didSelectRowAtIndexPath:

[self.navigationController pushViewController:level4a animated:NO]; //Push the level 4 first
NSMutableArray* mutableViewControllers = [self.navigationController.viewControllers mutableCopy];
[mutableViewController addObject:level3a atIndex:3]; //Add the level 3 manually
self.navigationController.viewControllers = mutableViewControllers;
[mutableViewControllers release];
0

精彩评论

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

关注公众号