0

I have a main menu made up of buttons within collection view cells, these are populated by a plist.

Im wanting these 5 buttons to send me to their corresponding websites but through one seque to the one webview.

I have the URLs stored in the same Plist the menu is populated by. So what I am wanting is:

once the Facebook button is pressed, it will request the URL from the Plist and pass it to the WebView which will display Facebook.

once the twitter button is pressed, it will request the URL from the Plist and pass it the the WebView etc etc

Thanks in advance.

Requested in Swift please.

user4682589
  • 49
  • 1
  • 2
  • 13

1 Answers1

2

I can cut down your problem into 3:

1. Retrieve the URL from the plist

You can see how to do it here: Retrieve data from plist

2. Depending on your the button clicked, you need to load the corresponding URL

What you should do is connect the 5 buttons to the same @IBAction func, and differentiate between the buttons with either the title of the button, or the tag

@IBAction func buttonIsClicked(sender: AnyObject) {
     print(sender.currentTitle.text)
     print(sender.tag) // tag assigned from the Interface builder to the button
     switch (sender.tag!) {
     case: 1: webviewInstance.loadRequest(NSURLRequest(URL: NSURL(string: "facebook.com")!))
     case: 2: webviewInstance.loadRequest(NSURLRequest(URL: NSURL(string: "twitter.com")!))
     }
}

By the way, you can assign tags to button like this: Assign Tag to button

3. Load your URL in a website

You can see how to do it here: How to load URL in UIWebView in Swift?

Community
  • 1
  • 1
Guy Daher
  • 5,526
  • 5
  • 42
  • 67
  • Thank you for your response, the trouble I have with that method is that I only have one button within one cell, this is then populated by the Plist which gives me my menu, therefore I cannot assign tags I also can't do it depending on button title. – user4682589 Feb 12 '16 at 10:20
  • Gotcha! Can you please post the code for how you are creating your menu? (the CustomCell in case you created a cell, the cellForRowAtIndexPath method in the UITableView etc). Like this, I can help you better. – Guy Daher Feb 12 '16 at 17:10