您的位置:首页 > 产品设计 > UI/UE

iOS 学习笔记 九 (2015.04.02)IOS8中使用UIAlertController创建警告窗口

2015-04-02 17:15 417 查看
1、IOS8中使用UIAlertController创建警告窗口

#pragma mark - 只能在IOS8中使用的,警告窗口
- (void)showOkayCancelAlert
{
NSString *title = NSLocalizedString(@"修改组名", nil);
NSString *message = NSLocalizedString(@"请输入新的组名", nil);
NSString *cancelButtonTitle = NSLocalizedString(@"取消", nil);
NSString *otherButtonTitle = NSLocalizedString(@"确定", nil);

UIAlertController *alertController = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert];
[alertController addTextFieldWithConfigurationHandler:^(UITextField *textField)
{
textField.backgroundColor = [UIColor lightTextColor]; // 可以在这里对textfield进行定制,例如改变背景色
}];

UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:cancelButtonTitle style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
NSLog(@"%s------%d-----点击取消按钮", __FUNCTION__, __LINE__);
}];
[alertController addAction:cancelAction];

UIAlertAction *otherAction = [UIAlertAction actionWithTitle:otherButtonTitle style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
UITextField *textField = alertController.textFields[0]; // 获取输入框中的新的组名
if ( textField.text.length == 0 )
{
[[[UIAlertView alloc] initWithTitle:@"提示" message:@"您的新群组名不合理" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil] show];
return;
}
NSLog(@"%s------%d-----点击确定按钮-----textField.text = %@", __FUNCTION__, __LINE__, textField.text);
[[SingleClient sharedInstanceClient] ClientAlterGroupInfor:(int)self.curGroup.g_02_gid gname:textField.text]; // 向服务器发送修改组名的请求
}];
[alertController addAction:otherAction];

[self presentViewController:alertController animated:YES completion:nil];
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: