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或自定義提示框更方便點。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM