从一个控制器移动到另一个控制器时出现未知错误?

时间:2016-04-29 05:43:48

标签: ios objective-c uibutton presentviewcontroller

在我的应用程序中,我使用此代码从一个控制器移动到另一个控制器时出现未知错误

-(IBAction)backQA:(id)sender
{
UIAlertController *alert =[UIAlertController alertControllerWithTitle:@"Attention" message:@"Are You Sure Quit The Exam!" preferredStyle:UIAlertControllerStyleAlert];


 UIAlertAction *ok = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
 ContestViewController *contestVC =[self.storyboard instantiateViewControllerWithIdentifier:@"ContestVC"];
 [self presentViewController:contestVC animated:YES completion:nil];

}];
UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action)     {

}];
[alert addAction:ok];
[alert addAction:cancel];
[self presentViewController:alert animated:YES completion:nil];
}

当我点击我的确定操作时,我收到错误。

这是屏幕截图,

enter image description here

任何帮助?

这是我的setMainBanner方法。

- (void)viewDidLoad
 {
    @try
    {
       if((NSNull *)[contestDict objectForKey:@"mainbanner"] != [NSNull null])
        {
            if([[contestDict objectForKey:@"mainbanner"] length] > 0)
             {
               NSString *mainBannerimage = [contestDict objectForKey:@"mainbanner"];
               NSString *bannerImageURL = [NSString stringWithFormat:@"http://www.karo.com/APP/banners/%@", mainBannerimage];
               NSURL *imageURL = [NSURL URLWithString:bannerImageURL];
            [mainBanner sd_setImageWithURL:imageURL
                               placeholderImage:[UIImage imageNamed:@"profilepic_bg"]];
              }
        else
        {

        }
    }
}
 @catch (NSException *exception)
 {

 }
}

2 个答案:

答案 0 :(得分:-1)

试试这个:

UIAlertController *alertController = [UIAlertController
                              alertControllerWithTitle:alertTitle
                              message:alertMessage
                              preferredStyle:UIAlertControllerStyleAlert];

UIAlertAction *cancelAction = [UIAlertAction 
            actionWithTitle:NSLocalizedString(@"Cancel", @"Cancel action")
                      style:UIAlertActionStyleCancel
                    handler:^(UIAlertAction *action)
                    {
                      NSLog(@"Cancel action");
                    }];

UIAlertAction *okAction = [UIAlertAction 
            actionWithTitle:NSLocalizedString(@"OK", @"OK action")
                      style:UIAlertActionStyleDefault
                    handler:^(UIAlertAction *action)
                    {
                      NSLog(@"OK action");
                    }];

[alertController addAction:cancelAction];
[alertController addAction:okAction];

最后,我们可以像任何其他视图控制器一样呈现警报视图控制器:

[self presentViewController:alertController animated:YES completion:nil];

答案 1 :(得分:-2)

为什么你使用presentViewController使用这个

 [self dismissViewControllerAnimated:YES completion:nil];