0

我在 ViewDidLoad 中创建了一个 UIAlertView,如下所示:

    prompt = [[UIAlertView alloc] init];
    prompt.title = @"تسجيل الدخول";
    prompt.message = @"\n\n\n";
    prompt.delegate = self;
    [prompt addButtonWithTitle:@"الغاء"];
    [prompt addButtonWithTitle:@"دخول"];

    userNameTxtField = [[UITextField alloc] initWithFrame:CGRectMake(12.0, 50.0, 260.0, 25.0)];  
    [userNameTxtField setBackgroundColor:[UIColor whiteColor]]; 
    [userNameTxtField setPlaceholder:@"اسم المستخدم"]; 
    [prompt addSubview:userNameTxtField];

    passwordTxtField = [[UITextField alloc] initWithFrame:CGRectMake(12.0, 85.0, 260.0, 25.0)];  
    [passwordTxtField setBackgroundColor:[UIColor whiteColor]]; 
    [passwordTxtField setPlaceholder:@"كلمة المرور"]; 
    [passwordTxtField setSecureTextEntry:YES]; 
    [prompt addSubview:passwordTxtField];

    [prompt show];  
    //[prompt release];

    // set cursor and show keyboard 
    [userNameTxtField becomeFirstResponder];

clickedButtonAtIndex 函数如下:

 -(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
if (buttonIndex ==0) {
    NSLog(@"cancel");
}else {
    NSLog(@"will login isA");
}
}

但是当我单击任何按钮时,我会看到输出,然后应用程序崩溃并给我以下异常:

   [MaktabatyTableViewController respondsToSelector:]: message sent to deallocated instance 0x894cfa0

有什么帮助吗???

4

1 回答 1

0

我试过你的代码。您的代码运行良好。

-(void)viewDidLoad
{

    UIAlertView *prompt = [[UIAlertView alloc] init];
    prompt.title = @"تسجيل الدخول";
    prompt.message = @"\n\n\n";
    prompt.delegate = self;
    [prompt addButtonWithTitle:@"الغاء"];
    [prompt addButtonWithTitle:@"دخول"];

    UITextField *userNameTxtField = [[UITextField alloc] initWithFrame:CGRectMake(12.0, 50.0, 260.0, 25.0)];
    [userNameTxtField setBackgroundColor:[UIColor whiteColor]];
    [userNameTxtField setPlaceholder:@"اسم المستخدم"];
    [prompt addSubview:userNameTxtField];

    UITextField *passwordTxtField = [[UITextField alloc] initWithFrame:CGRectMake(12.0, 85.0, 260.0, 25.0)];
    [passwordTxtField setBackgroundColor:[UIColor whiteColor]];
    [passwordTxtField setPlaceholder:@"كلمة المرور"];
    [passwordTxtField setSecureTextEntry:YES];
    [prompt addSubview:passwordTxtField];

    [prompt show];
    //[prompt release];

    // set cursor and show keyboard
    [userNameTxtField becomeFirstResponder];
}
于 2012-09-17T13:55:23.660 回答