尝试使用子视图中的按钮来关闭presentViewController

时间:2012-12-24 13:42:35

标签: objective-c ios ipad

基本上我有两个xib,第一个是主xib,其中包含一个触发IBAction调用的按钮:

UIViewController *overlaywindow = [[UIViewController alloc] initWithNibName:@"NewInvenView" bundle:nil];
overlaywindow.modalPresentationStyle = UIModalPresentationFormSheet;
overlaywindow.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;

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

这会产生我想要的结果。

然而,在NewInvenView.xib中,我正在尝试创建一个可以解除自身的按钮(并关闭PresentingView)。我将按钮与NewInvenViewController.h链接,并在NewInvenViewController.m中实现该方法。但是当我运行它时,它不起作用。

每当触发按钮时,都会调用该函数,但是我收到错误:

  

2012-12-24 20:33:50.984 Dokodemo [1467:907] * 终止应用程序   未捕获的异常'NSInvalidArgumentException',原因:   ' - [UIViewController filterstock:]:发送到的无法识别的选择器   实例0x21033990'...

我认为同样重要的是要注意,无论函数实现内部是什么,我都会收到错误。即使功能无效

为什么会这样?

2 个答案:

答案 0 :(得分:0)

如果您使用navigationController进行翻转动画,那将很容易。

 -(void)goToNextView:(id)sender{

          NextView *info3 = [[NextView alloc]initWithNibName:@"NextView" bundle:nil];
            UINavigationController * nvc = [[UINavigationController alloc] initWithRootViewController:info3];

            info3.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
            [self.navigationController presentModalViewController:nvc animated:YES];

        }

//如果您使用最新版本的iOS,请更改以下内容

[self.navigationController presentViewController:nvc animated:YES completion:nil];

第二个视图中的

控制器您可以使用它来关闭。

-(IBAction)goToPrevious:(id)sender

{

[self.navigationController dismissModalViewControllerAnimated:YES];

// For latest Version

// [self.navigationController dismissViewControllerAnimated:YES completion:nil];
}

答案 1 :(得分:0)

我认为问题与nib文件有关。如果您检查错误消息,则会显示-[UIViewController filterstock:]:,这表示邮件会发送到UIViewController而非NewInvenViewController的对象。

确保从检查器窗格中的nib文件中正确设置类。