trio
trio

Reputation: 647

Why won't self.navigationController pushViewController work?

I have a

UIViewController-> UINavigationBar + UITableView

Just a bit more explanation

I made it through UIBuilder..

1: Created a New UIViewController with XIB-file
2: Using UIBuiler i put a UINavigationController
3: Then i put UITableView underneath the navigationBar so it gave me..

A: UIViewController-> UINavigationBar + UITableView

Now i am loading the data in UITableView from a Webservice which is working fine.

I again made a xib with sam config which is

B: UIViewController-> UINavigationBar + UITableView

So now when i try to push view B on view A using below code...it wont at all work...

SelectSiteViewController *siteViewController = [[SelectSiteViewController alloc] initWithNibName:@"SelectSiteViewController" bundle:nil];

[self.navigationController pushViewController:siteViewController animated:YES];

When i checked the UINavigationController *nav = self.navigation

nav is 0x0 that is i assume NIL.

Can anybody tell me whats wrong in here.. why is it nil...and how can i make it work..

Thanks a Lot....I would really appreciate any help

Upvotes: 2

Views: 28845

Answers (4)

sundsx
sundsx

Reputation: 618

why UIViewController-> UINavigationBar + UITableView ?

I suggest you another approach ->UITableViewController A -> Embedded with a Navigation Controller, then after populate tableview you can pass data to ->UITableViewController B by [[self storyboard]instantiateViewControllerWithIdentifier:@"ControllerB"];

then, in storyboard, drop a tableView B and in Identity->storyboard Id put some id.

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath   *)indexPath
{
NSString *sUrl= @"<#string#>";
if (indexPath.row == 0) sUrl= @"http://www.apple.com/";
if (indexPath.row == 1) sUrl= @"http://www.google.com/";
if (indexPath.row == 2) sUrl= @"http://www.times.uk/";

NSMutableArray *selectedObject = [arrayOpenMale objectAtIndex:0];
NSLog(@"%@ is the selected object.",selectedObject);

SeriesAdetailVC *dvc = [[self  storyboard]instantiateViewControllerWithIdentifier:@"DetailView"];
dvc.strings7 = [NSURL URLWithString:sUrl];

[self.navigationController pushViewController:dvc animated:YES];

}

hope help

Upvotes: 0

Bourne
Bourne

Reputation: 10302

So you are adding the tableview to the navigation controller right? This is how:

tableView = [[UITableViewController alloc] initWithStyle:UITableViewStylePlain];

navigationController = [[UINavigationController alloc] init];

[navigationController pushViewController:tableView animated:NO];

The tableview gets added as the rootview to the navigation controller. And then on selecting a row if you wish to push another viewcontroller use the

self.navigationController pushViewController: newViewController animated:YES]; 

inside the didSelectRowAtIndex method.

NOTE: its UITableViewController *tableView and UINavigationController *navigationController by declaration. So code accordingly for your table.

Upvotes: 1

trio
trio

Reputation: 647

Got it.

I changed the Architecture a little bit.

I made a New UIViewController class with its xib. And coded new UINavigationController.

- (void)viewDidLoad {
[super viewDidLoad];
    UINavigationController *navigationController
navigationController = [[UINavigationController alloc] init];
[self.view addSubview:navigationController.view];   


switch (whichViewController) {
    case 1:
        viewController = [[xxxx alloc] init];           
        break;
    case 2:
        viewController = [[xxx1 alloc] init];           
        break;
    default:
        break;
}

[navigationController pushViewController:viewController animated:NO];
[viewController release];

}

And pushing the view in the Switch Statement....

I hope this makes sense ......

Thanks jamihash

Upvotes: 2

jamihash
jamihash

Reputation: 1900

In UIBuilder verify that UINavigationController is referenced by the File's owner.

Upvotes: 3

Related Questions