ios - 将数据上传到 Parse.com 时,UIAlertView 似乎卡住了应用程序

标签 ios xcode parse-platform uialertview ibaction

您好,我正在使用解析来帮助我的 iOS 应用程序的后端,我创建了一个按钮,它将我的文本保存在我的文本字段中,并在我单击按钮时将其上传到云端。

按钮和弹出的警报代码如下

- (IBAction)savebutton:(id)sender {
// Create PFObject with recipe information
PFObject *recipe = [PFObject objectWithClassName:@"GolfTimes"];
[recipe setObject:_nameTextField.text forKey:@"Name"];
[recipe setObject:_prepTimeTextField.text forKey:@"MemberNumber"];

[recipe setObject:_NumberOfGolfers.text forKey:@"NumberOfGolfers"];

[recipe setObject:_RequestedTime.text forKey:@"RequestedTime"];


NSArray *ingredients = [_ingredientsTextField.text componentsSeparatedByString: @","];
[recipe setObject:ingredients forKey:@"Telephone"];

// Show progress
MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
hud.mode = MBProgressHUDModeIndeterminate;
hud.labelText = @"Sending...";
[hud show:YES];

// Upload recipe to Parse
[recipe saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
    [hud hide:NO];

    if (!error) {
        // Show success message
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Request Sent" message:@"We will get back to you with confirmation." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
        [alert show];

        // Notify table view to reload the recipes from Parse cloud
        [[NSNotificationCenter defaultCenter] postNotificationName:@"refreshTable" object:self];

        // Dismiss the controller
        [self dismissViewControllerAnimated:YES completion:nil];

    } else {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Upload Failure" message:[error localizedDescription] delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
        [alert show];

    }

}];}

尽管数据确实正确发送并且 View Controller 确实像我所做的那样关闭,但警报似乎卡住了应用程序,我大部分时间都无法单击“确定”。当我单击“确定”按钮时,应用程序模拟器将关闭。

有什么建议或帮助吗?

最佳答案

我相信您需要发送UIAlertView当你想显示它们时,像这样到主线程:编辑:您不能拥有 UIAlertView 的代表上UIViewController你刚刚解雇了!这就是它崩溃的原因;将代表设置为: nil 应该可以解决这个问题。

dispatch_async(dispatch_get_main_queue(),^
{
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Request Sent" message:@"We will get back to you with confirmation." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
    [alert show];   

    [[NSNotificationCenter defaultCenter] postNotificationName:@"refreshTable" object:self];

    [self dismissViewControllerAnimated:YES completion:nil];
});

关于ios - 将数据上传到 Parse.com 时,UIAlertView 似乎卡住了应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24976979/

相关文章:

ios - 快速点击主页按钮时调用函数

ios - UIView addSubview 工作一次但不能工作两次

ios - 忽略随机 subview 的 UIAppearance 代理而不是整个类

ios - Jenkins 上的 XCode 项目,停留在 "codesign"

Android 推送通知未接收/未发送

ios - 从 Parse-Server 传输到 dynamoDB。有哪些可预见的障碍?

ios - 如何创建一个打开/关闭 collectionView 部分

ios - CloudKit 记录保存进度

parse-platform - 您如何为解析服务器配置 emailAdapter?

xcode - 当 .app 在桌面上运行时,NSFileManager 的 currentDirectoryPath 返回根目录