UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Please Login" message:@"กรุณากรอก ชื่อผู้ใช้ และ รหัสผ่าน " delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Login", nil]; [alert setAlertViewStyle:UIAlertViewStyleLoginAndPasswordInput]; [alert show]; [alert release];
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex { UITextField *username = [alertView textFieldAtIndex:0]; UITextField *password = [alertView textFieldAtIndex:1]; lblUsername.text = [username text]; lblPassword.text = [password text];; }
// // 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 *lblPassword; IBOutlet UILabel *lblUsername; } - (IBAction)btnLogin:(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 { [lblUsername release]; [lblPassword release]; [super dealloc]; } - (IBAction)btnLogin:(id)sender { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Please Login" message:@"กรุณากรอก ชื่อผู้ใช้ และ รหัสผ่าน " delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Login", nil]; [alert setAlertViewStyle:UIAlertViewStyleLoginAndPasswordInput]; [alert show]; [alert release]; } - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex { NSString *title = [alertView buttonTitleAtIndex:buttonIndex]; if([title isEqualToString:@"Login"]) { UITextField *username = [alertView textFieldAtIndex:0]; UITextField *password = [alertView textFieldAtIndex:1]; lblUsername.text = [username text]; lblPassword.text = [password text];; } if([title isEqualToString:@"Cancel"]) { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Alert!" message:@"Your Select Cancel" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil]; [alert show]; [alert release]; } } @end
ช่วยกันสนับสนุนรักษาเว็บไซต์ความรู้แห่งนี้ไว้ด้วยการสนับสนุน Source Code 2.0 ของทีมงานไทยครีเอท