user1904273
user1904273

Reputation: 4764

Can you dynamically create link in IOS

I am trying to tag an item in IOS. On the item page, I'd like to have a link to the tag. However, the screen for the tag varies based on the tag.

Example, for an item of clothing, if it is tagged, shirt, I'd like the shirt tag to point to the shirt page, if the tag is jacket, I'd like to point to the jacket tag etc.

For this reason, I cannot hardwire a segue in Storyboard to a given view controller. Can anyone suggest a way to point to different view controllers based on the tag.

Thanks in advance for any suggestions.

Upvotes: 0

Views: 35

Answers (2)

Abhinav
Abhinav

Reputation: 38162

Assuming, in your storyboard, you have view controller pages defined for all your tags,

  1. In your storyboad, start a segue directly from the source view controller to all possible destination view controllers. e.g. item page to shirt page, item page to jacket page etc.
  2. Select each of your segue and give a suitable segue identifier for this segue. I would advise to use your tag names like shirtPage, jacketPage etc.
  3. Finally, in your source view controller (item page) implement performSegueWithIdentifier:sender: like this

->

-(IBAction)linkButtonPressed:(id)sender {  
    if (shirtPageCondition == YES) {
       [self performSegueWithIdentifier:@"shirtPage" sender:nil];  
    } else if (jacketPageCondition == YES) {
       [self performSegueWithIdentifier:@"jacketPage" sender:nil];  
    }  
}

Upvotes: 1

Jason Nam
Jason Nam

Reputation: 2011

There are various methods and properties of UIViewController you can chose

Presenting View Controllers
modalPresentationStyle [Property]
modalTransitionStyle [Property]
modalInPopover [Property]
- showViewController:sender:
- showDetailViewController:sender:
- presentViewController:animated:completion:
- dismissViewControllerAnimated:completion:
definesPresentationContext [Property]
providesPresentationContextTransitionStyle [Property]
- disablesAutomaticKeyboardDismissal

Also you can instantiate view controllers with Storyboard or just UIViewController classes yourself in the code.

For example

let shirtViewController: ShirtViewController = UIStoryboard(name: "Shirt", bundle: NSBundle.mainBundle()).instantiateInitialViewController() as! ShirtViewController

presentViewController(shirtViewController, animated: true, completion: nil)

Upvotes: 0

Related Questions