gpt4 book ai didi

ios - 模态关闭后显示错误消息

转载 作者:行者123 更新时间:2023-11-28 22:04:34 25 4
gpt4 key购买 nike

所以就像问题所暗示的那样,我试图在用户向服务器发送一些数据后不卡住 UI。就我而言,他们可能会发送大量数据,而服务器端我必须为多个查询执行 foreach 循环。

虽然发生了所有这些,但我不希望用户等待响应,因此我在单击“发送”后关闭模态 VC。数据仍然被插入到数据库中,但如果出现错误怎么办?现在我在模态 VC 被关闭后显示一个 UIAlertView 但我得到一个错误的访问错误。显示错误的最佳方式是什么?

- (void)send:(id)sender{
if ([[Data sharedInstance].someData objectForKey:@"time"] != NULL) {
[self dismissViewControllerAnimated:YES completion:^(){
NSMutableDictionary *paramDic = [NSMutableDictionary new];
[paramDic setValue:[[Data sharedInstance].someData objectForKey:@"oneArray"] forKeyPath:@"oneArray"];
[paramDic setValue:[NSArray arrayWithObjects:[[[Data sharedInstance].someData objectForKey:@"two"] valueForKey:@"Name"], [[[Data sharedInstance].someData objectForKey:@"two"] valueForKey:@"State"], [[[Data sharedInstance].someData objectForKey:@"two"] valueForKey:@"Country"], nil] forKeyPath:@"twoArray"];
[paramDic setValue:[[[Data sharedInstance].someData objectForKey:@"three"] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding] forKeyPath:@"three"];
[paramDic setValue:[[NSUserDefaults standardUserDefaults] valueForKey:@"username"] forKey:@"username"];
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:paramDic options:NSJSONWritingPrettyPrinted error:nil];
NSURL *url = [NSURL URLWithString:@"http://localhost/myapp/handleData.php"];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[request setHTTPMethod:@"POST"];
[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
NSString *length = [NSString stringWithFormat:@"%d", jsonData.length];
[request setValue:length forHTTPHeaderField:@"Content-Length"];
[request setValue:@"json" forHTTPHeaderField:@"Data-Type"];
[request setHTTPBody:jsonData];
[NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *error){
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse*)response;
if (![httpResponse statusCode] == 200 || ![[[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding] isEqualToString:@"success"]) {
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Error" message:@"Problem on the server. Please try again later." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[alert show];
}
}];
}];
}

我现在就是这样做的...什么是更好的方法?

最佳答案

以上回答很有值(value)。但我认为这是导致问题的原因。

改变:

UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Error" message:@"Problem on the server.  Please try again later." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];

收件人:

UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Error" message:@"Problem on the server.  Please try again later." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];

希望这对您有所帮助。

关于ios - 模态关闭后显示错误消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24329361/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com