【发布时间】:2026-01-03 04:35:01
【问题描述】:
我已经创建了请求,我想在收到成功消息作为响应时弹出视图。这是我的代码:
NSURLSession *session = [NSURLSession sharedSession];
NSString *baseURLRequest = [NSString stringWithFormat:@"%@/email_addr=%@",mySession.baseURL,self.txtEmail.text];
NSURLSessionDataTask *dataTask = [session dataTaskWithURL:[NSURL URLWithString:baseURLRequest] completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
NSDictionary *dict = [json objectForKey:@"result"];
NSString *msg = [dict objectForKey:@"msg"];
if ([[dict objectForKey:@"status"] isEqualToString:@"success"])
{
dispatch_async(dispatch_get_main_queue(), ^{
[self showMesssgeonAlert:@"Success"];
[self hideProgress];
[self.navigationController popViewControllerAnimated:YES];
});
}
else
{
}
}];
[dataTask resume];
下面不工作,
[self.navigationController popViewControllerAnimated:YES];
有人知道为什么会这样吗? UINavigation controller 对于viewControllers 也是相同的。请帮帮我,谢谢。
【问题讨论】:
-
检查 ([[dict objectForKey:@"status"] isEqualToString:@"success"]) 是否成功并检查 self.navigationcontroller 是否为非 nil
-
检查
self.navigationController是否为nil -
if [self showMesssgeonAlert:@"Success"];和 [self hideProgress];调用方法请检查您的 navigationController 可能为零。你有没有在故事板中嵌入导航控制器????
-
@vinoth [self.navigationController popViewControllerAnimated:YES];这必须从最后一行删除
-
是的,这是我的错误,我已修复。谢谢:)
标签: ios objective-c iphone popviewcontroller