您好,我正在使用解析来帮助我的 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/