3

I have two view controller FirstVC and SecondVC. i have a table view in FirstVC. I simply want to push my view on SecondVC by clicking on any cell of FirstVC table view. I am using storyboard for this view. i don't have separate NIB file for the view.

Thanks in adv.

Bhavin_m
  • 2,746
  • 3
  • 30
  • 49

2 Answers2

2

In the FirstVC tableview delegate,

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{
     SecondVC *objSecondVC = [[SecondVC alloc] initWithNIBName: @"SecondVC" bundle: nil];
     [self.navigationController pushViewController: objSecondVC animated: YES];
     [objSecondVC release];
     objSecondVC = nil;
}

Please don't forget to import the SecondVC in FirstVC header as

#import "SecondVC.h"
Mathew Varghese
  • 4,527
  • 2
  • 17
  • 26
  • as i mention in title i am using "storyboard". i don't have separate NIB file for that view. i create two view on same storyboard. – Bhavin_m Jul 04 '12 at 10:25
  • sorry for the misunderstanding. try `LoginViewController *controller = [self.storyboard instantiateViewControllerWithIdentifier:@"LoginIdentifier"]; [self.navigationController pushViewController:controller animated:YES];` – Mathew Varghese Jul 04 '12 at 10:29
  • you can see the answer question in these [thread](http://stackoverflow.com/questions/8348109/how-can-i-manually-switch-between-uiviewcontrollers-in-storyboard) – Mathew Varghese Jul 04 '12 at 10:30
  • just add a navigation controller before your FirstVc and try the same code ,it will work. – Ab'initio Jul 04 '12 at 11:04
2

enter image description hereIf you are using storyboard then just control click and drag from tableview cell to the nextviewcontroller and select push from drop down.

Nuzhat Zari
  • 3,398
  • 2
  • 24
  • 36
  • Have you added navigation controller or your tableview is embeded with navigationcontroller?I think it is not thats why you are not able to push.Just select tableview in storyboard, go to editor, select Embed In option, then select Navigation Controller this will embed your tableview in navigation controller you will able to push it. – Nuzhat Zari Jul 04 '12 at 12:01
  • i have not added navigation controller. i simply add new navigation controller in storyboard and assign my FirstVC to rootViewcontroller. It solved my push problem. Thanks for your guide..... – Bhavin_m Jul 04 '12 at 12:38