UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Confirm!" message:@"Do you want to Cancel?" delegate: self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK", nil]; [alert show]; [alert release];
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex { if(buttonIndex == 0) { lblResult.text = @" Your selected Cancel."; }else if(buttonIndex == 1) { lblResult.text = @" Your selected OK."; } }
// // ViewController.h // // Created by Weerachai on 10/27/55 BE. // Copyright (c) 2555 Weerachai. All rights reserved. // #import <UIKit/UIKit.h> @interface ViewController : UIViewController { IBOutlet UILabel *lblResult; } - (IBAction)btnConfirm:(id)sender; @end
// // ViewController.m // // Created by Weerachai on 10/27/55 BE. // Copyright (c) 2555 Weerachai. All rights reserved. // #import "ViewController.h" @interface ViewController () @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } - (void)dealloc { [lblResult release]; [super dealloc]; } - (IBAction)btnConfirm:(id)sender { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Confirm!" message:@"Do you want to Cancel?" delegate: self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK", nil]; [alert show]; [alert release]; } - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex { if(buttonIndex == 0) { lblResult.text = @" Your selected Cancel."; }else if(buttonIndex == 1) { lblResult.text = @" Your selected OK."; } } @end
ช่วยกันสนับสนุนรักษาเว็บไซต์ความรู้แห่งนี้ไว้ด้วยการสนับสนุน Source Code 2.0 ของทีมงานไทยครีเอท