Navigation Based Application with TabBar

后端 未结 3 1562
醉梦人生
醉梦人生 2021-01-14 06:50

I have a Navigation-Based Application that shows a TableView where you can select a cell and it brings you to a \"Detail View\" for that cell. I want this view to then have

相关标签:
3条回答
  • 2021-01-14 06:55

    You should be aware that it's possible Apple will reject your application if you do this though.

    From "Combining Tab Bar and Navigation Controllers"

    It’s very common to combine tab bar and navigation controllers, as illustrated in Figure 4. To do this, you simply add navigation controllers to a tab bar controller (however, you should never add a tab bar controller to a navigation controller).

    So it's likely to be against the Human Interface guidelines and so could you get rejected.

    0 讨论(0)
  • 2021-01-14 07:00

    Basically What you need to do is push a Tab View Controller onto the Navigation Controller's viewcontroller stack.

    Starting with a fresh "Navigation-Based Application" template. I added the following method in RootViewController.m :

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    //Navigation logic may go here. Create and push another view controller.
    UIViewController *viewOneViewController =   [[UIViewController alloc] init];
    viewOneViewController.title = @"One";
    viewOneViewController.view.backgroundColor = [UIColor redColor];
    
    UIViewController *viewTwoViewController =   [[UIViewController alloc] init];
    viewTwoViewController.title = @"Two";
    viewTwoViewController.view.backgroundColor = [UIColor orangeColor];
    
    UIViewController *viewThreeViewController = [[UIViewController alloc] init];
    viewThreeViewController.title = @"Three";
    viewThreeViewController.view.backgroundColor = [UIColor greenColor];
    
    UITabBarController *anotherViewController = [[UITabBarController alloc] init];
    anotherViewController.viewControllers = [NSArray arrayWithObjects:viewOneViewController, viewTwoViewController, viewThreeViewController, nil];
    [self.navigationController pushViewController:anotherViewController animated:YES];
    [anotherViewController release];
    

    }

    Changed this to 25 to test:

    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
        return 25;
    }
    

    Now when I build and run I'll see what you are looking for in a basic way. What you will want to do after you get this working is to change the UIViewControllers to Custom Subclasses that you create to hold the code for each view. (If you are also using Interface Builder, change the init to initWithNibNamed:).

    Hope this helps you get on your way a bit.

    0 讨论(0)
  • 2021-01-14 07:22

    I'm trying to do this very same thing. The application "Tweetie" is doing something similar. They have a TableView of accounts and then you select an account and TabBar appears.

    Anyways, straight from Apple's Documentation:

    pushViewController:animated: Pushes a view controller onto the receiver’s stack and updates the display.

    • (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated

    Parameters viewController The view controller that is pushed onto the stack. It cannot be an instance of tab bar controller. This method does nothing if the view controller is already on the stack.

    animated Set this value to YES to animate the transition. Pass NO if you are setting up a navigation controller before its view is displayed.

    So maybe we're just stuck using a TabBar and not a TabBarController?

    -JP

    0 讨论(0)
提交回复
热议问题