views:

28

answers:

1

I am trying to implement a modal navigation controller as described in the Apple iOs Guide http://tinyurl.com/2fswaul

I have come to the conclusion that I am missing something both obvious and stupid as I simply cannot get anything to display, I get a blank white screen.

Swapping things out I can prove that the view controller that I am using as the navigation controllers RootViewController works fine on it's own (by adding it manually as a view subChild).

Further, implementing addSubView ([self.view addSubview:navController.view]) instead of presentModalViewController seems to work OK.

Can anyone point out my simple error because I am 5 minutes short of kicking my own face :D

header

#import <UIKit/UIKit.h>

@interface BaseViewController : UIViewController {

}

implementation

#import "BaseViewController.h"
#import "ScannedListViewController.h"
#import "ScannedItemViewController.h"

@implementation BaseViewController

- (void)viewDidLoad {

    ScannedListViewController *listViewController = [[ScannedListViewController alloc] init];
    ScannedItemViewController *itemViewController = [[ScannedItemViewController alloc] init];

    UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:listViewController];
    [navController pushViewController:itemViewController animated:NO];

    [self presentModalViewController:navController animated:YES];

    [listViewController release];
    [itemViewController release];
    [navController release];

    [super viewDidLoad];

}

The RootControllerView is a basic test TableViewController with the following header

@interface ScannedListViewController : UITableViewController <UITableViewDelegate, UITableViewDataSource>

Thank you in advance if your able to help

A: 

Why are you presenting something modally in a view controller's viewDidLoad method? I find that odd off the top. Generally you show a modal view controller in response to some action (like tapping a button).

Is there a reason you're showing a navigation controller with a second view controller already pushed on it after the root?

You should have [super viewDidLoad] as the first line, not the last line, of the method.

You do not need to have <UITableViewDelegate, UITableViewDataSource> after UITableViewController because it already adopts those protocols. Remove that bit.

Shaggy Frog
Hmm.. Well the desired outcome is to load the application, show a view for 5 seconds and then progress on to the main part of the app which is a three page form controlled by a navigationController. Perhaps I have been misled as to the approach I should take. The second view controller pushed on is straight from Apples example. I assumed I was building a view stack, as I have not been able to see the results I didn't realise that wasn't best practice!
lucygenik
If you intend to show a view for 5 seconds and then modally show another view, you will not accomplish that by doing it inside `viewDidLoad`. You'll have to use an `NSTimer` and set its callback to a method that pushes the modal view.
Shaggy Frog
Thank you Shaggy, that worked perfectly. I need to work on my understanding of view lifecycles!
lucygenik
Glad I could be of help -- now all you have to do is upvote this answer and check it "answered" :)
Shaggy Frog