尝试弹出xib(ipad)并在打开后关闭

时间:2014-08-20 18:50:26

标签: ios objective-c

我有一个主viewController xib,并且根据用户点击它的按钮可以将它们带到4个viewControllers xib之一我看过这段代码并且似乎有错误。

iOS: Returning to main XIB from secondary XIB

- (IBAction)Button100:(id)sender
{
    [self.aView removeFromSuperview];
    self.aView = nil;
}

如果@property (strong) UIView *aView;进入主appdeligte或者只是在第一个xib的主.h文件中,它可以在第二个xib中找到aView吗?

1 个答案:

答案 0 :(得分:0)

所以我理解你只想根据点击的按钮显示和隐藏适当的视图。

一种方法是将它放在你的根视图控制器中:

-(IBAction) buttonXClicked {
    [self presentModalViewController:someViewController animated:YES];
}

(我在此假设您已经知道如何将按钮与其动作相关联,如果没有,请阅读本教程:http://rshankar.com/different-ways-to-connect-ibaction-to-uibutton/

然后在您的子视图中:

-(IBAction) backButtonClicked {
    [self dismissModalViewControllerAnimated:YES];
}

另一种方式(虽然没有动画)在你的根视图控制器中:

-(IBAction) buttonXClicked {
    [self.view addSubview:someViewController.view];
}

并在子视图中:

-(IBAction) buttonXClicked {
    [self.view removeFromSuperview];
}

我还建议您查看本教程使用导航控制器(看起来应该更好):

http://iosmadesimple.blogspot.com/2012/09/navigation-based-project-doing-it-using.html