2012年5月13日 星期日

UIAlertView

  目的:點選按鈕出現訊息視窗


step1. 畫面加入“button”及“label”元件

step2. ViewController.h 
@interface ViewController : UIViewController
{
    IBOutlet id mylab;
}
-(IBAction)onClick:(id)sender;
@end


step3. ViewController.m
@implementation ViewController
-(IBAction)onClick:(id)sender {
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"訊息標題" message:@"請選擇" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"儲存", @"產生", nil];
   
    [alert show];
   
}
-(void)alertView:(UIAlertView *)sender clickedButtonAtIndex:(NSInteger)buttonIndex {
    switch (buttonIndex) {
        case 0:
            [mylab setText:@"cancel"];
            break;
        case 1:
            [mylab setText:@"save"];
            break;  
        case 2:
            [mylab setText:@"load"];
            break;     
        default:
            break;
    }
}