警示框

點擊按鈕彈出警示框
- (IBAction)login:(UIButton *)sender {
    UIAlertView * alert = [[UIAlertView alloc]initWithTitle:@"輸入賬號密碼" message:nil delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"確定", nil];//delegate屬性賦值爲self,也就是view controller,所以在view controller中需要實現代理功能,就是alert view: :
    alert.alertViewStyle = UIAlertViewStyleLoginAndPasswordInput;
    [alert show];
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:
(NSInteger)buttonIndex{
    switch (buttonIndex) {
        case 0:
            NSLog(@"Cancel button clicked");
            break;
        case 1:{
            NSLog(@"OK button clicked");
            UITextField * text1 = [alertView textFieldAtIndex:0];
            UITextField * text2 = [alertView textFieldAtIndex:1];
            NSLog(@"賬號爲:%@",text1.text);
            NSLog( @"%@",text2.text);
            _textt.text = text1.text;
            //_textt.textContainer = text2.text
            //[_textt.text stringByAppendingFormat:@"%@",text2.text];
            //取警示框上的數據
            break;
        }
        default:
            break;
    }
}

//不斷彈出
-(void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
{//這裏彈出一個警示框的時候,點擊確定時,又會調用委託對象的方法,而此處委託用的是和前一個委託相同,所以會調用相同的方法,報錯
    UIAlertView * alert1 = [[UIAlertView alloc]initWithTitle:@"密碼錯誤!!!" message:nil delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"確定", nil];
    alert1.alertViewStyle = UIAlertViewStyleDefault;
    [alert1 show];
//    UITextView
    //下面是自己寫的,搞惡作劇用,不斷彈出警示框,可以寫上各種信息,最後來一個自動關機之類的動作。
    UIAlertView * alert = [[UIAlertView alloc]initWithTitle:@"輸入賬號密碼" message:nil delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"確定", nil];
    alert.alertViewStyle = UIAlertViewStyleLoginAndPasswordInput;
    
    [alert show];
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章