UIAlertView
一.
UIAlertView(警报)以蓝色圆角矩形都形式出现在屏幕的中部,警报可显示一个或多个按钮。
- (void)viewDidLoad {
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:@”Hello”
message:@”This is an alert view”
delegate:self
cancelButtonTitle:@”OK”
otherButtonTitles:nil];
[alert show];
[alert release];
[super viewDidLoad];
}
initWithTitle:@”Hello”
message:@”This is an alert view”
delegate:self
cancelButtonTitle:@”OK”
otherButtonTitles:nil];
[alert show];
[alert release];
[super viewDidLoad];
}
二.
#import <UIKit/UIKit.h>
@interface UsingViewsViewController : UIViewController
<UIAlertViewDelegate> {
}
@end
<UIAlertViewDelegate> {
}
@end
- (void)viewDidLoad {
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:@”Hello”
message:@”This is an alert view”
delegate:self
cancelButtonTitle:@”OK”
otherButtonTitles:@”Option 1”, @”Option 2”, nil];
[alert show];
[alert release];
[super viewDidLoad];
}
initWithTitle:@”Hello”
message:@”This is an alert view”
delegate:self
cancelButtonTitle:@”OK”
otherButtonTitles:@”Option 1”, @”Option 2”, nil];
[alert show];
[alert release];
[super viewDidLoad];
}
- (void)alertView:(UIAlertView *)alertView
clickedButtonAtIndex:(NSInteger)buttonIndex {
NSLog(@”%d”, buttonIndex);
}
NSLog(@”%d”, buttonIndex);
}
OK button — 0
Option 1 — 1
Option 2 — 2