0

I'm developing an iOS app and I have a big problem...

I need to have a tableview inside viewController (that's why I can not use UiTableViewController) and I can't use static cells. I solved that creating a NSMutableArray and loading each cell in my cellForRowAtIndexPath.

So, what's my problem?

In swrevealviewcontroller tutorials (like http://www.appcoda.com/ios-programming-sidebar-navigation-menu/) they use segues for navigation when pushing cells, so, How can I create segues dinamically?

I tried to use

MyNewVC *myNewVc=[self.storyboard instantiateViewControllerWithIdentifier:@"homeVC"];
[self.navigationController pushViewController:myNewVc animated:YES];

but it doesn't work.

Thanks!!

Aarranz
  • 461
  • 6
  • 20

3 Answers3

1

Why not just create a generic segue and use that? It doesn't need to be connected to a cell or a UI control. That way your code will work as long as the segue identifier is correct.

Robert J. Clegg
  • 7,231
  • 9
  • 47
  • 99
  • But how can I do it? I only know how to create a segue in my storyboard, and that means, that I connect my prototype cell with one view controller, and I need 6 different view controllers – Aarranz May 10 '14 at 07:31
  • 1
    At the bottom of your screen / view controller in storyboard there is a yellow icon - ctrl + drag from there to another view controller. Give the segue an identifier. Then just repeat this step for all the other view controllers. Don't connect it to the cell – Robert J. Clegg May 10 '14 at 07:53
  • No problem. Accept the answer if it helped. It lets everyone else know which answer worked. – Robert J. Clegg May 10 '14 at 11:37
0

You need to link the segues from the view controller to their destinations then use the view controller's preformSegueWithIdentifier: method. See this: Understanding performSegueWithIdentifier

Community
  • 1
  • 1
iamamused
  • 2,720
  • 3
  • 25
  • 17
0
[self presentViewController:magnifiedVC animated:YES completion:^{
    //place block to run here, such as assigning properties
}];

It is not a segue, but another way of keeping track of view controllers. you can then dismiss the destination view controller by doing this in a destination view controller method:

[self.presentingViewController dismissViewControllerAnimated:YES completion:nil];

This means you will have instantiate the destination view controller in your presenting view controller, which you do not need to with a segue I afaik.

EDIT1: In that case, you can use instantiateViewControllerWithIdentifier: to allocate and prepare the view controller, and then use performSegueWithIdentifier:. you will then need to use core data or plists to store the state of each view controller everytime you perform a segue to prevent the sending controller from being unloaded and released and losing its data. you can do this in the prepareForSegue:.

note: you can not use storyboard instantiated view controllers for use on the navigation controller

Michael Lorenzo
  • 628
  • 10
  • 20
  • Thanks!I didn't know that it was possible to do that. I think is really usefull for "about" views for example, but in my case,it is a bad programming practice because my tableview is a menu. When my users push in a cell, they will navigate to another view whit the same tableviw, so if they navigate a lot, they will have multiple views one in front of each other – Aarranz May 10 '14 at 08:00