navigation_Controller

Things to remember while implementing a navigation controller

1) Take a navigation controller and allocate the  memory first.

navcontroller =[[UINavigationController alloc]init];

2) allocate the view controller with the nib name

_viewController = [[ViewController alloc] initWithNibName:@”ViewController” bundle:nil];

3)Add the ViewController to the Navigation Controller

[navcontroller pushViewController:_viewController animated:YES];

4)add the navigation controller as a subview

[self.window addSubview:navcontroller.view];

//now you just got ur view with a navigation controller

//still we have to implement the navigation from one view to another.

 

 

now we got the navigation for bar for the view..in order to get the navvigation to the another view use the [self.navigationController pushViewController : viewcontrolerobj];

 

sample code:

 

– (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

{

self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];

// Override point for customization after application launch.

self.viewController = [[[ViewController alloc] initWithNibName:@”ViewController” bundle:nil] autorelease];

nav=[[UINavigationController alloc]initWithRootViewController:self.viewController];

self.window.rootViewController = nav;

[self.window makeKeyAndVisible];

return YES;

}

 

nextview is a viewcontroller with a tableview

 

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

{

return 8;

}

 

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

{

subViewController *sub=[[subViewController alloc]initWithNibName:@”subViewController” bundle:Nil];

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

//[self presentModalViewController:nav animated:YES];

[sub release];

}

 

 

– (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

static NSString *cellIdentifier=@”CellIdentifier”;

UITableViewCell *cell=[table dequeueReusableCellWithIdentifier:cellIdentifier];

if (cell==Nil) {

cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];

}

cell.textLabel.text=@”abhii”;

return cell;

}