ben*_*e89 2 cocoa-touch objective-c app-store uialertview ios
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"An Alert!"
delegate:self cancelButtonTitle:@"OK" otherButtonTitles:[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://phobos.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=301349397&mt=8"]];];
[alert show];
[alert release];
Run Code Online (Sandbox Code Playgroud)
我正在尝试使用一个"Ok"按钮和一个"Buy Full Version"按钮显示UIAlertView.如何使上述代码有效?
谢谢
您需要处理UIAlertViewDelegate指定的按钮单击.
此外,otherButtonTitles仅仅是一个va_list的NSString对象作为标题使用,可以设置当他们在被窃听发生的事情UIAlertViewDelegate的alertView:clickedButtonAtIndex:方法:
- (void) alertView:(UIAlertView *) alertView clickedButtonAtIndex:(NSInteger) index {
if(index == 1) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://phobos.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=301349397&mt=8"]];
}
}
Run Code Online (Sandbox Code Playgroud)
别忘了设置delegate:
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"An Alert!"
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:@"Buy Full Version"];
[alert show];
[alert release];
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2721 次 |
| 最近记录: |