【问题标题】:Instance method '-presentViewController:animated' not found找不到实例方法“-presentViewController:animated”
【发布时间】:2013-04-19 01:53:15
【问题描述】:

我对此很陌生,所以请耐心等待。我的代码中有 2 个错误需要修复。在这两种情况下都找不到我的实例方法:

-(IBAction)goFlipSide {
    NSLog(@"goFlipSide has been called:");
    FlipsideViewController *controller = [[FlipsideViewController alloc] initWithNibName:@"FlipsideViewController" bundle:nil];

    controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
    [self presentViewController:controller animated:YES];

    [controller release];
}

- (void)flipsideViewControllerDidFinish:(FlipsideViewController *)controller {
    [self dismissViewControllerAnimated:YES];

    //This method gets fired when the user clicks done on the modal FlipsideViewController.  This is different
    //than the viewWillAppear.
    self.navigationController.navigationBarHidden = TRUE;
    /*
    if (self.goViewSuccess == TRUE) {
        //if the goViewSuccess boolean is set to YES - then we can load the load the goViewController
        NSLog(@"goViewSuccess is YES");
        [self loadGoViewController];
    }
    */
}

未找到的两个实例方法是:presentViewController:dismissViewControllerAnimated:

【问题讨论】:

  • 谁是self(这些方法属于哪个类)?
  • 查看UIViewController 的文档。查看以presentViewController开头的方法。你缺少一个论点。
  • steinm10:据我所知,您是在 iOS6.1 中编写代码。 presentViewController:controller animated:YESdismissViewControllerAnimated:YES 方法在 iOS6.1 中已弃用

标签: ios objective-c cocoa-touch uiviewcontroller


【解决方案1】:

self 是什么类?这些方法只能在UIViewController 上找到。完整的选择器是:

  • presentViewController:animated:completion:
  • dismissViewControllerAnimated:completion:

尝试添加完成块参数。

【讨论】:

  • 如果您不需要完成块,只需传递nil
【解决方案2】:

代码应该是这样的

[self dismissViewControllerAnimated:YES completion:nil];

或者,如果您在完成后想要一些东西,

[self dismissViewControllerAnimated:YES completion:^{
//do stuff
}];

对于另一个

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-13
    • 1970-01-01
    相关资源
    最近更新 更多