2011-04-04 48 views
0

我有一个应用程序,它具有从我的主视图通过一些定制的UIButtons导航到的许多视图。主视图命名为iBMRViewController,并以通过界面构建​​器放入的PNG图像形式提供了一些欢迎图形。它还具有6个自定义UIButtons,我通过使用以下代码创建了它们;使用一个IBAction切换回主视图控制器

// This is the code which creates, and defines the properties of the 'Warning' button on the main view. 
    UIButton *warningButton = [[UIButton buttonWithType:UIButtonTypeRoundedRect] retain]; 
    warningButton.frame = CGRectMake(225.0, 270.0, 60.0, 60.0); 
    [warningButton setTitle:@"" forState:UIControlStateNormal]; 
    warningButton.backgroundColor = [UIColor clearColor]; 
    [warningButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal ]; 
    UIImage *warningButtonImageNormal = [UIImage imageNamed:@"Warning.png"]; 
    UIImage *warningStretchableButtonImageNormal = [warningButtonImageNormal stretchableImageWithLeftCapWidth:12 topCapHeight:0]; 
    [warningButton setBackgroundImage:warningStretchableButtonImageNormal forState:UIControlStateNormal]; 
    UIImage *warningButtonImagePressed = [UIImage imageNamed:@"whiteButton.png"]; 
    UIImage *warningStretchableButtonImagePressed = [warningButtonImagePressed stretchableImageWithLeftCapWidth:12 topCapHeight:0]; 
    [warningButton setBackgroundImage:warningStretchableButtonImagePressed forState:UIControlStateHighlighted]; 
    [warningButton addTarget:self action:@selector(warningButtonAction:) forControlEvents:UIControlEventTouchUpInside]; 
    [self.view addSubview:warningButton]; 

现在,这一切工作正常,按钮功能完美,显然我也有行动为他们设置完美的工作。在每一页上,我都有一个UINavigationBar和一个UINavigationItem,通过界面构建​​器进行设置,并设置为使用下面的代码将我带回到主视图;

//This is the code which opens up the new view when 'Begin' button is tapped. 
-(IBAction)beginHomeButtonAction:(id)sender { 
    iBMRViewController *controller = [[BeginView alloc] initWithNibName:@"iBMRViewController" bundle:nil]; 
    controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal; 
    [self presentModalViewController:controller animated:YES]; 
    [controller release]; 

这也适用,但是,当它把我带回到了“iBMRViewController”它只显示什么通过Interface Builder的XIB文件(即欢迎PNG文件)成立。它不显示我通过代码添加的按钮。

任何人都可以告诉我哪里出了问题吗?将不胜感激。

感谢

回答

0

事实上,beginHomeButtonAction不“带你回到主视图”。它创建一个新的视图控制器,并提供一个新的视图。它与控制器类的类似,但不同于该类的实例

要关闭视图,并且实际上将用户带回主视图,您必须关闭从主视图呈现的视图。如何做到这一点取决于你如何呈现,但你可以尝试popViewControllerAnimateddismissModalViewControllerAnimated。 (谷歌是你的朋友)

+0

谢谢。我会尽力理解你刚才说的笑话。当我明白他在说什么时,谷歌确实是我的朋友。但这个术语对我来说都是比较新的,所以有时很难。我想我对你在说什么有所了解,所以我会试一试。谢谢 – 2011-04-05 10:41:05

+0

没错。如有疑问,请在您的原始问题中张贴介绍子视图的代码。 – mvds 2011-04-05 10:44:06

+0

我设法解决这个问题,而不是在我的IBAction中使用这段代码 - iBMRViewController * controller = [[BeginView alloc] initWithNibName:@“iBMRViewController”bundle:nil]; - 我将[[BeginView alloc]更改为[[iBMRViewController alloc]),它就像一个魅力。 – 2011-04-06 14:56:01

相关问题