【发布时间】:2011-04-04 23:08:40
【问题描述】:
我有一个应用程序,它有许多视图,这些视图通过我的主视图中的一些自定义 UIButtons 导航到。主视图名为 iBMRViewController,并具有一些通过界面生成器放入的 PNG 图像形式的欢迎图形。它还具有 6 个自定义 UIButton,我使用以下代码通过代码创建;
// 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”时,它只显示通过界面构建器 xib 文件(即欢迎 png 文件)设置的内容。它不显示我通过代码添加的按钮。
谁能告诉我我哪里出错了?将不胜感激。
谢谢
【问题讨论】:
标签: iphone objective-c xcode interface-builder