为什么我没有得到 UIAlertView

Why I am not getting UIAlertView

我正在为 sign-in/sign-up 进程使用解析。

一切正常。直到用户提供错误的详细信息。

我在 Parse Login 的 else 部分写了:

self.view.userInteractionEnabled = YES;

[SVProgressHUD dismiss];
// The login failed. Check error to see why.
NSString *message = [NSString stringWithFormat:@"%@",[error valueForKey:@"Error"]];
UIAlertView *myalert = [[UIAlertView alloc]initWithTitle:@"SO" message:message delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles: nil];
[myalert show];

我在每一行都设置了断点后进行了检查。

执行第 3 行后,即 NSSString *message 控件不会发出警报,它直接显示 UI,没有任何警报框。

在日志中我得到

[Error]: invalid login parameters (Code: 101, Version: 1.7.5)

我不知道该怎么办?我在else部分只写了这段代码。

我正在使用解析代码:

[user signUpInBackgroundWithBlock:^(BOOL succeeded, NSError *error) 
{
    if (!error) 
    {   
        // Hooray! Let them use the app now.
    } 
    else 
    {   
        NSString *errorString = [error userInfo][@"error"];   // Show the errorString somewhere and let the user try again.
    }
}];

在其他部分我想显示和 alertView

试试这个代码

NSString *errorString;
UIAlertView *AV;
[user signUpInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
  if (!error) {   // Hooray! Let them use the app now.
  } else {   errorString = [error userInfo][@"error"];   // Show the errorString somewhere and let the user try again.
      AV = [[UIAlertView alloc]initWithTitle:@"SO" message:errorString delegate:nil cancelButtonTitle:@"Cancel" otherButtonTitles:nil, nil];
      [AV show];
  }
}];

试试这个:

UIAlertView *myalert = [[UIAlertView alloc]initWithTitle:@"SO" message:message delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles: nil];
 dispatch_async(dispatch_get_main_queue(), ^(void){
           [myalert show];
    });

尝试先调用主线程,然后在其中创建 UIAlert

因为大多数情况下,当您不在主线程中时就会发生这种情况

希望这能解决你的问题,祝你好运