出现第二个模态视图控制器的问题

时间:2013-03-16 18:45:44

标签: ios objective-c

目前我的错误说我的视图控制器已经显示为null。我认为我对下面的代码有正确的想法,但我没有正确实现它。谢谢你的帮助

  -(IBAction)datePicker
{
    //UIViewController *presenter = self.presentingViewController;

    [self dismissViewControllerAnimated:YES completion:^{
        /*
        UIStoryboard*  sb = [UIStoryboard storyboardWithName:@"MainStoryboard.storyboard"
                                                      bundle:nil];
        UIViewController* dateView = [sb instantiateViewControllerWithIdentifier:@"DatePickerViewController"];

         */

        [self performSegueWithIdentifier:@"dueDateSegue" sender:self];
        //[presenter presentViewController:dateView animated:YES completion:nil];

        /*
        [self presentViewController:dateView animated:YES completion:^{

            UIBarButtonItem *saveDate = [[UIBarButtonItem alloc]
                                         initWithTitle:@"Save Date"
                                         style:UIBarButtonItemStyleDone
                                         target:self
                                         action:@selector(labelDatePicker)];
            self.navigationItem.rightBarButtonItem = saveDate;
            pick = [[UIDatePicker alloc] init];
            [pick setFrame:CGRectMake(0,200,320,120)];
            //[pick addTarget:self action:@selector(done) forControlEvents:UIControlEventValueChanged];
            //dateFieldText.delegate = self;
            //dateFieldText.inputView = pick;

        }];
         */

    }];

}

1 个答案:

答案 0 :(得分:0)

在方法datePicker中,添加以下行作为第一行代码:

UIViewController *presenter = self.presentingViewController;

然后而不是:

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

尝试使用:

 [presenter presentViewController:dateView animated:YES completion:nil];