obj-c UIAlertView

来源:互联网 发布:融合网络 英文 编辑:程序博客网 时间:2024/03/29 09:00

#import <UIKit/UIKit.h>


@interface ViewController :UIViewController<UIAlertViewDelegate>


- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex;


@end



- (void)viewDidLoad

{

    [superviewDidLoad];

    

   UIAlertView *view=[[UIAlertViewalloc] initWithTitle:@"标题"message:@"信息异常" delegate:self

                                      cancelButtonTitle:@"取消"otherButtonTitles:@"确定",nil];

    [view setAlertViewStyle:UIAlertViewStylePlainTextInput];

 

   UITextField *textField=[view textFieldAtIndex:0];

    

    textField.keyboardType=UIKeyboardTypeNamePhonePad;

    

    [viewshow];

   

    view =nil;

    // Do any additional setup after loading the view, typically from a nib.

}

-(void) alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex

{

    

   UITextField *textField=[alertView textFieldAtIndex:0];

   NSLog(@"输入的文字%@",textField.text);

    

    

  if(buttonIndex==1)

   {

       NSLog(@"你点击的是第一个按钮");

   }

   else

    {

        NSLog(@"你点击的是第二个按钮");

    }

}