`
jsntghf
  • 浏览: 2517998 次
  • 性别: Icon_minigender_1
  • 来自: 苏州
社区版块
存档分类
最新评论

iOS5中的UIAlertView

    博客分类:
  • iOS
阅读更多

iOS5中提供了几种便利的UIAlertView,如下所示:

 

- (IBAction)showDefaultAlertView:(id)sender {    
    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"DefaultStyle" 
                                                        message:@"the default alert view style"
                                                       delegate:self 
                                              cancelButtonTitle:@"Cancel" 
                                              otherButtonTitles:@"OK", nil];    
    [alertView show];
    [alertView release];
}

- (IBAction)showSecureTextAlertView:(id)sender {
    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"SecureTextStyle" 
                                                        message:@"Enter secure text"
                                                       delegate:self 
                                              cancelButtonTitle:@"Cancel" 
                                              otherButtonTitles:@"OK", nil];    
    alertView.alertViewStyle = UIAlertViewStyleSecureTextInput;
    [alertView show];
    [alertView release];
}

- (IBAction)showPlainTextAlertView:(id)sender {    
    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"PlainTextStyle" 
                                                        message:@"Enter plain text"
                                                       delegate:self 
                                              cancelButtonTitle:@"Cancel" 
                                              otherButtonTitles:@"OK", nil];    
    alertView.alertViewStyle = UIAlertViewStylePlainTextInput;
    [alertView show];
    [alertView release];
}

- (IBAction)showLoginPassAlertView:(id)sender {    
    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"LoginAndPaswordStyle" 
                                                        message:@"Enter login and password"
                                                       delegate:self 
                                              cancelButtonTitle:@"Cancel" 
                                              otherButtonTitles:@"OK", nil];    
    alertView.alertViewStyle = UIAlertViewStyleLoginAndPasswordInput;
    [alertView show];
    [alertView release];
}

 

下面是对应的代理方法:

 

- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex {
    switch (alertView.alertViewStyle) {
        case UIAlertViewStylePlainTextInput:
        {
            UITextField *textField = [alertView textFieldAtIndex:0];
            NSLog(@"Plain text input: %@", textField.text);
        }
            break;
            
        case UIAlertViewStyleSecureTextInput:
        {
            UITextField *textField = [alertView textFieldAtIndex:0];
            NSLog(@"Secure text input: %@", textField.text);
        }
            break;
            
        case UIAlertViewStyleLoginAndPasswordInput:
        {
            UITextField *loginField = [alertView textFieldAtIndex:0];
            NSLog(@"Login input: %@", loginField.text);
            
            UITextField *passwordField = [alertView textFieldAtIndex:1];
            NSLog(@"Password input: %@", passwordField.text);
        }
            break;
            
        default:
            break;
    }
}

- (BOOL)alertViewShouldEnableFirstOtherButton:(UIAlertView *)alertView {
    UIAlertViewStyle style = alertView.alertViewStyle;
    
    if ((style == UIAlertViewStyleSecureTextInput) ||
        (style == UIAlertViewStylePlainTextInput) ||
        (style == UIAlertViewStyleLoginAndPasswordInput)) {
        UITextField *textField = [alertView textFieldAtIndex:0];
        if ([textField.text length] == 0) {
            return NO;
        }
    }
    
    return YES;
}
分享到:
评论

相关推荐

    swift-因为iOS8以后UIAlertView已经不推荐使用

    在iOS8及之后的版本中,苹果推荐开发者使用`UIAlertController`来替换`UIAlertView`,因为`UIAlertController`提供了更强大的功能和更好的自定义性。 `UIAlertView`在早期的iOS版本中是用于展示警告或提示用户信息...

    ios UIAlertView修攺其布局,自定义UIAlertView

    在iOS开发中,`UIAlertView`是苹果提供的一种用于显示简单警告信息或用户确认操作的原生弹窗。然而,系统默认的`UIAlertView`存在一定的局限性,比如它最多只支持两个按钮,并且按钮布局固定,这在某些场景下可能...

    ios7 自定义UIAlertView

    在iOS开发中,UIAlertView是苹果提供的一种用于显示警告或询问用户简单信息的原生控件。然而,随着iOS系统的更新,特别是从iOS7开始,UIAlertView的样式和使用方式发生了一些变化,开发者有时需要对其进行自定义以...

    IOS之UIAlertView的事件处理(免Delegate)

    在iOS开发中,`UIAlertView`是苹果提供的一种用于显示简单警告对话框的UI组件,通常包含一个标题、一条消息和一到两个按钮。在早期版本的iOS中,`UIAlertView`的事件处理通常需要通过实现其代理方法来完成,这增加了...

    ios-自定义UIAlertView虚化.zip

    UIAlertView是iOS中的一个基础组件,用于显示警告或确认消息。然而,随着iOS 8的发布,UIAlertView被UIAlertController取代,因为后者提供了更多的自定义选项和更好的适应性。STAlertView可能是对这个变化的一种响应...

    ios-类似UIAlertView自定义.zip

    在iOS开发中,`UIAlertView`曾经是用于展示警告或询问用户简单信息的默认视图,但自iOS 8之后,苹果弃用了这个类,转而推荐使用`UIAlertController`。然而,有时候开发者可能仍需要创建类似`UIAlertView`的自定义弹...

    ios-UIalertView.zip

    在iOS开发中,UIalertView是苹果提供的一种原生控件,用于向用户显示警告或确认信息,通常包含一个标题、消息文本以及一个或多个按钮。在这个"ios-UIalertView.zip"压缩包中,我们可能找到了一个针对UIAlertView的...

    自定义 UIAlertView

    在iOS开发中,UIAlertView曾是系统提供的一种用于展示警告或提示信息的标准组件,但在iOS 8之后被UIAlertController所取代。然而,在某些场景下,开发者可能仍需要自定义UIAlertView来实现特定的界面风格或者功能...

    Android仿IOS UIAlertView对话框demo

    在iOS中,UIAlertView通常用于显示简单的警告、确认或输入信息的弹窗,而Android开发者在没有官方提供的类似组件时,需要自行实现这样的功能。 这篇博文(http://blog.csdn.net/zhufuing/article/details/18735371...

    ios-简单的UIAlertView.zip

    5. **注意点**:从iOS 8开始,UIAlertView被弃用,取而代之的是UIAlertController。UIAlertController提供了更多的灵活性,可以容纳更多类型的视图,如文本字段、开关等,并且支持自定义样式。因此,对于新项目,...

    ios-UIAlertView封装.zip

    5. **兼容性考虑**:由于`UIAlertView`在iOS 8后被弃用,封装可能已经包含了兼容新旧系统的代码,确保在所有支持的iOS版本上都能正常工作。 6. **错误处理**:封装可能也包含了错误处理机制,当无法正确显示`...

    ios-imitate - UIAlertView.zip

    在iOS开发中,`UIAlertView`曾经是用于展示警告或询问用户信息的标准组件,但自iOS 8之后,它被`UIAlertController`所取代。然而,有些开发者可能仍希望保持`UIAlertView`的简单使用方式,因此`ios-imitate - ...

    ios-swift - UIAlertView的使用.zip

    在iOS开发中,`UIAlertView`是苹果提供的一种用于向用户显示简单警告或确认信息的UI组件。这个组件在Swift编程语言中广泛应用于弹出视图的场景,例如提示用户保存数据、确认操作或者显示错误信息。`UIAlertView`虽然...

    ios-400行自定义UIAlertView.zip

    https://github.com/STShenZhaoliang/STAlertView 400行写的自定义UIAlertView,没有开太多接口,大家可以自由修改。

    iOS开发6:UIActionSheet与UIAlertView

    在iOS开发中,UIActionSheet和UIAlertView是两种常用的用户交互组件,它们用于向用户提供警告、确认或选择。在iOS 5.1版本中,这两种组件是进行用户界面交互的重要工具。 UIActionSheet通常用于呈现一组有限的选项...

    UIAlert:使用 UIAlertView (iOS <= 7) 或 UIAlertViewController (iOS >= 8) 的 iOS 的简单 UIAlert

    使用 UIAlertView (iOS <= 7) 或 UIAlertViewController (iOS >= 8) 的 iOS 的简单 UIAlert Objective-C 类。 ##一些实现信息 由于 ARC 和UIAlertView内部操作块的使用,ARC 在调用show后删除了创建的消息。 ...

    iOS UIAlertView自动关闭功能

    在iOS开发中,`UIAlertView`是用于向用户显示简单警告或确认消息的原生组件。然而,`UIAlertView`默认并不支持自动关闭功能,即它会在用户点击按钮后消失。但在某些情况下,开发者可能希望在特定时间间隔后自动关闭...

    ios的提示信息UIActionSheet和UIAlertView

    在iOS开发中,UIActionSheet和UIAlertView是两种用于向用户展示提示信息的重要控件。它们在用户交互过程中起到了至关重要的作用,特别是在需要用户做出选择或确认操作时。然而,随着iOS版本的更新,这两种控件逐渐被...

    iOS中UIAlertView3秒后消失的两种实现方法

    在iOS开发中,`UIAlertView` 是一个常用的控件,用于显示简单的警告或提示信息。然而,有时我们希望在用户不需要进行任何操作的情况下,这个警告视图能够在一段时间后自动消失。本篇文章将详细介绍两种方法来实现在...

Global site tag (gtag.js) - Google Analytics