0

I have a View Controller with a UIImage inside and a button that links to a url. I added 2 more images and a Swipe Gesture as a transition between them. The images are setup as profiles, and the button is supposed to direct the user the web url of that profile. Is there a way to customize the button's url according to the current image in the view?

user3592174
  • 13
  • 1
  • 3
  • This question is unclear. Please update your question with more details about what you are actually trying to do to the button. Post relevant code if needed. Point out what issue you are having with the code if you do. – rmaddy May 10 '14 at 23:31

1 Answers1

0

This will depend a lot on how what exactly your Swipe Gesture is doing to show the new images.

If the gesture is simply updating the UIImage inside a single UIImageView, you could have an array of URLs corresponding to each profile. When a swipe occurs, you could update an instance variable, and on button press, you could use that instance variable as a reference into the URL array.

@property (nonatomic) int currentIndex;
@property (nonatomic, retain) NSArray *urls;

- (IBAction)showProfile:(id)sender {
    NSURL *url = self.urls[self.currentIndex];
    // Use the url
}

Alternatively, if you have three separate UIImageViews, you'll need to have three different buttons. You could connect each of them to the same action, and switch on the "sender".

NSURL *url;
if (sender == self.firstButton) {
    url = self.urls[0];
} else if (sender == self.secondButton) {
    url = self.urls[1];
}
// Other button cases

// Use the url
  • could I connect them to their own separate web views in separate View Controllers? – user3592174 May 10 '14 at 23:53
  • Absolutely! Though this may be an entirely different question in itself. You'll need to create some way of transitioning from the current view controller to a new one. I'd advise using a storyboard, and setting up a segue for the transition. You can pass the URL object to the new controller as described in this post: http://stackoverflow.com/questions/7864371/ios-how-to-pass-prepareforsegue-an-object – user3624393 May 14 '14 at 21:55
  • Thanks guys! I actually decided to try enabling/disabling the buttons according to the imageIndex using if statements, and it worked perfectly! Thanks for your help!! – user3592174 May 25 '14 at 04:12