Reputation: 3
I want it once the user taps the 'otherbutton' it goes to my link. But at the moment once the button is pressed it doesn't do anything.
Sorry im on my iPhone so I've used pastebin for the code
Thanks alot
Upvotes: 0
Views: 654
Reputation: 55354
You need to set the UIAlertView
's delegate
property to self
instead of nil
and implement the protocol in the header.
Header File:
@interface MyViewController : UIViewController <UIAlertViewDelegate>
In addition, check for the buttonIndex
. Currently, (after performing the above), it will open the URL if any button is pressed.
- (void)alertView: (UIAlertView *)alertView clickedButtonAtIndex: (NSInteger)buttonIndex
{
if (buttonIndex != [alertView cancelButtonIndex])
{
//open url
}
}
Upvotes: 1
Reputation: 13371
Conform your controller class to the UIAlertViewDelegate protocol.
@interface MyViewController : UIViewController <UIAlertViewDelegate>
Create the alert view with delegate set to self:
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Follow" message:@"me on twitter" delegate:self cancelButtonTitle:@"No" otherButtonTitles:@"Yes", nil];
[alert show];
[alert release];
Respond to the delegate method
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex {
if (buttonIndex != [alertView cancelButtonIndex]) {
// open url
}
}
Upvotes: 1
Reputation: 8644
The delegate
of your UIAlertView
must be set to the class (self
in most cases) that's using it. Make sure your class calling the UIAlertView
does conform to the UIAlertViewDelegate
delegate.
Upvotes: 1