I want it once the user taps the 'otherbutton' it goes to my link. But at the mome开发者_运维百科nt once the button is pressed it doesn't do anything.
Sorry im on my iPhone so I've used pastebin for the code
http://pastebin.com/fvgk87ih
Thanks alot
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
}
}
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.
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
}
}
精彩评论