0

i wanted to ask, if i got one uitableviewcell, i need to do checking to meet the condition then only perform to different segue to different view, how to do it? Example like:

    if subCat[indexPath.row] == ""{

        performSegueWithIdentifier("A", sender: self)

    }else{

        performSegueWithIdentifier("B", sender: self)

    }

How to do it? And how should i connect it with segue at the storyboard?

luk2302
  • 55,258
  • 23
  • 97
  • 137
bobo
  • 121
  • 2
  • 10
  • Yes. Connect second segue to *view controller* same way as first. Your example looks ok. – Yury Aug 12 '16 at 09:23
  • @ShadowOf then how should i do it? any other way? – bobo Aug 12 '16 at 09:25
  • https://developer.apple.com/library/ios/referencelibrary/GettingStarted/DevelopiOSAppsSwift/Lesson8.html#//apple_ref/doc/uid/TP40015214-CH16-SW1 – Yury Aug 12 '16 at 09:26
  • @ShadowOf means only this way can only achieve by using navigation controller? – bobo Aug 12 '16 at 09:29
  • 1
    Is your question how to create the two segues that will be performed programmatically? Just control-drag from the view controller icon above the scene to the next scene, and then give the segue a storyboard id. See first half of http://stackoverflow.com/a/27650207/1271826. Just repeat that for the two segues. Then you can `performSegueWithIdentifier` in the `UITableViewDelegate` method, `didSelectRowAtIndexPath`. – Rob Aug 12 '16 at 09:31
  • Navigation controller not necessary. You need to explain in details what do you want to do and what have you tried to receive more detailed help. – Yury Aug 12 '16 at 09:34

1 Answers1

-1

Even you can do by giving storyboard identifier "A" to viewController 1 and "B" to viewController 2 and push you controller if using navigation otherwise simply present the viewcontroller.

if subCat[indexPath.row] == "" {
    let viewController1 = storyboard.instantiateViewControllerWithIdentifier("A") as! ViewController1

    // if navigation controller used.
    self.navigationController?.pushViewController(viewController1, animated: true)

    // if navigation controller not used.
    // self.presentViewController(viewController1, animated: true, completion: nil)
}else{
    let viewController2 = storyboard.instantiateViewControllerWithIdentifier("B") as! ViewController2

    // if navigation controller used.
    self.navigationController?.pushViewController(viewController2, animated: true)

    // if navigation controller not used.
    // self.presentViewController(viewController2, animated: true, completion: nil)
}
Bhautik Ziniya
  • 1,554
  • 12
  • 19