1

我正在尝试为用户创建一个登录名以输入他们的用户名和密码。我正在使用 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"];

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

任何帮助,将不胜感激。

谢谢!

4

1 回答 1

0

在这里做什么addTextFieldWithValue?下没有列出这样的方法UIAlertView

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

于 2012-12-13T17:41:31.677 回答