-1

I am new on iOS development, after completed some basic tutorials and beginner level books, i looked the examples of iOS programming. After that i found this.

https://github.com/uacaps/PageMenu

I downloaded examples, but i have a problem. I am using PageMenuDemoTabbar (https://github.com/uacaps/PageMenu/tree/master/Demos/Demo%204/PageMenuDemoTabbar) example. And i want to add segues when user clicked the tableviewcell. But here is the problem. Because tableviews created programmatically, i can't add segues from storyboard.

How i can accomplish this?

Thanks for help.

javasch
  • 1
  • 2

1 Answers1

1

If you want to go to another view controller from the Storyboard, just add StoryboardID to this view controller (like I have RootViewController with StoryboardID RootVC):

enter image description here

then create public property for the data you want to pass to the view controller (i.e. @property (nonatomic, strong) NSDictionary *propertyYouSet). And then add the following code in your -tableView:didSelectItemAtIndexPath: UITableView delegate method:

YourViewController *yourViewController = [[UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier:@"YourViewControllerStoryboardID"];
yourViewController.propertyYouSet = @{ 'someKey': 'someValueYouWantToPass' };

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

This way you can still use Storyboard view controllers without need of segue.

Swift version

Oops, just noticed the swift tag. So here is the same code in Swift:

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
    let storyboard = UIStoryboard(name: "Main", bundle: nil)
    let vc = storyboard.instantiateViewControllerWithIdentifier("yourViewControllerStoryboardID") as! UIViewController
    vc.setYourProperty(someDictionaryHere) // I'm not so sure about this, I'm new in Swift too :)
    self.presentViewController(vc, animated: true, completion: nil)
}

then override this method in your view controller:

init(coder aDecoder: NSCoder!)
{
    super.init(coder: aDecoder)
}

(because in Swift -initWithCoder: is required :) )

Lucifer
  • 480
  • 3
  • 12