开发者

iOS: TabBarController with two sub-views?

In my app, I want two modes that the user can choose from, using a tab bar controller. Buy view and Sell view. But in sell view and in buy view, there are several views each. "List of offers", "offer details", "make offer", etc.

I was thinking of changing the view belonging to the "sell view"-tab on button clicks, but that seems wrong.

What is the correct way to handle this? Should the "buy" and "sell" tabs each be linked to a view, which in turn contains an array of the several subviews list, details, make offer, etc.?

And how do I access the "sell" view from my "offer list" view button开发者_运维问答s?

Thx a bunch, MrB


In the simpliest form, the following will work

Each tab gets it's own UINavigation controller. Each navigation controller has it's own collection of UIViewControllers.

When the user clicks on a tab they are presented with the corresponding nav controller. Each nav controller could show a UITableViewController that has a selection of sub view controllers to select.

the following is semi-psuedo code.. fyi

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Override point for customization after application launch.

    UITabBarController *tbc = [[UITabBarController alloc]init];
    UIWindow *w = [[UIWindow alloc]initWithFrame:[[UIScreen mainScreen] bounds]];;
    self.window = w; //property defined in the .h file
    [w release];



    //add the TabBarControllers view to the window.. this will be presented to the user
    [self.window addSubview:tbc.view];


    //BUT.. the tab bar doesnt have any items to show.. lets solve that

    NSMutableArray *a = [[NSMutableArray alloc]init];

    // you should have two ViewControllers already created, ViewControllerA and ViewControllerB, or whetever you want to call them.
    // they should both inherit from UITableViewController (for our example)
    // then create two UINavigationControllers, initialize each one with the corresponding ViewController (ViewControllerA and B);
    // add each UINavigationController to our array above




    //assign our view controllers;
    tbc.viewControllers=a;
    [a release];



    [self.window makeKeyAndVisible];
    return YES;
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜