iOS UIAlertView添加输入框

这玩意有时不用就忘,还是记录一下吧

 

 

添加:

    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"新建文件夹" message:@"" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
    [alert setAlertViewStyle:UIAlertViewStylePlainTextInput];
    UITextField *txtName = [alert textFieldAtIndex:0];
    txtName.placeholder = @"请输入名称";
    [alert show];

  

代理点击处理:

#pragma mark - 点击代理
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    if (buttonIndex == 1) {
        UITextField *txt = [alertView textFieldAtIndex:0];
        //获取txt内容即可
        
    }

    
}

  

UIAlertView在iOS8之后被废弃了,系统建议用UIAlertController实现,实现更简单了

不过在一些纯View上显示提示框,还是用UIAlertView或自定义提示框更方便点。

posted @ 2016-09-01 17:40  那一抹风情  阅读(10984)  评论(0编辑  收藏  举报