使用 UIAlertView 创建登录视图



我正在尝试为用户创建一个登录名以输入他们的用户名和密码。 我正在使用Xcode 4.5。 这是我的 .h 文件代码:

    #import <UIKit/UIKit.h>
    #import "AccountViewController.m"
    @interface AccountViewController : UIViewController {

    }

    - (IBAction) alert: (id)sender;
    @end

这是我的 .m 文件代码:

    #import "AccountViewController.h"

    @implementation AccountViewController

    - (IBAction)alert:(id)sender
    {
    UIAlertView *alert =[[UIAlertView alloc] initWithTitle:@"Log In" message:@"Please enter      your    Username and Password" delegate:self cancelButtonTitle:@"Log In"         otherButtonTitles:@"Cancel", nil];
    [alert addTextFieldWithValue:@"" label:@"Username"];
    [alert addTextFieldWithValue:@"" label:@"Password"];
    UITextField *tf = [alert textFieldAtIndex:0];
    tf.clearButtonMode = UITextFieldViewModeWhileEditing;
    tf.keyboardType = UIKeyboardTypeAlphabet;
    tf.keyboardAppearance = UIKeyboardAppearanceAlert;
    tf.autocapitalizationType = UITextAutocapitalizationTypeWords;
    tf.autocorrectionType = UITextAutocorrectionTypeNo;
    tf = [alert textFieldAtIndex:1];
    tf.clearButtonMode = UITextFieldViewModeWhileEditing;
    tf.keyboardType = UIKeyboardTypeURL;
    tf.keyboardAppearance = UIKeyboardAppearanceAlert;
    tf.autocapitalizationType = UITextAutocapitalizationTypeWords;
    tf.autocorrectionType = UITextAutocorrectionTypeNo;
    [alert show];

    }
    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
    }

    - (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning]; // Releases the view if it doesn't have a superview
    // Release anything that's not essential, such as cached data
    }

    - (void)dealloc {
    }

    @end

以下每行代码的 .m 文件中都发生此错误:

    [alert addTextFieldWithValue:@"" label:@"Username"];
    [alert addTextFieldWithValue:@"" label:@"Password"];

错误是:没有可见的@interface"UIAlertView"声明选择器"addTextFieldWithValue:label:"

任何帮助将不胜感激。

谢谢!

addTextFieldWithValue在这里做什么?UIAlertView 下没有列出此类方法。

另外,如果您要处理警报按钮上的点击事件,请将UIAlertViewDelegate包含在您的班级中。

最新更新