Iphone 按UIButton将新视图推到导航堆栈上
我现在有一个附加了视图的窗口,它有三个UIButton。当用户按下按钮时,我希望使用NavigationController将视图更改为新视图 现在我把about按钮编码如下:Iphone 按UIButton将新视图推到导航堆栈上,iphone,uinavigationcontroller,uibutton,Iphone,Uinavigationcontroller,Uibutton,我现在有一个附加了视图的窗口,它有三个UIButton。当用户按下按钮时,我希望使用NavigationController将视图更改为新视图 现在我把about按钮编码如下: UIButton *aboutButton = [UIButton buttonWithType:UIButtonTypeCustom]; aboutButton.frame = CGRectMake(236, 240, 60, 60); [aboutButton setImage:[UIImage imageNamed
UIButton *aboutButton = [UIButton buttonWithType:UIButtonTypeCustom];
aboutButton.frame = CGRectMake(236, 240, 60, 60);
[aboutButton setImage:[UIImage imageNamed:@"About.png"]
forState:UIControlStateNormal];
[aboutButton addTarget:self action:@selector (aboutButtonPressed)
forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:aboutButton];
对于动作功能:
-(void)aboutButtonPressed {
UINavigationController *aboutView =[[UINavigationControlleralloc] initWithNibName:@"About" bundle:nil];
[self.navigationController pushViewController:aboutView animated:YES];
[self.view addSubview:aboutView.view];
[aboutView release];
}
About.xib文件当前没有任何内容
现在来谈谈这个问题。。。当按下按钮时,顶部导航栏会出现在顶部,但不会像我编码的那样以动画的形式出现。它突然出现了。此外,没有返回按钮返回到带有按钮的视图。我做错了什么?我可以提供更多的代码或细节,如果这是不够清楚
编辑:这里有一张图片,可以更好地了解正在发生的事情
单击“关于”按钮后:
编辑2:删除了一些不应该出现的返回按钮的不可靠代码。按ViewController后的大多数代码看起来都不可靠
-(void)aboutButtonPressed {
AboutViewController *aboutView =[[AboutViewController **alloc**] initWithNibName:@"About" bundle:nil];
[self.navigationController pushViewController:aboutView animated:YES];
[aboutView release];
}
这至少会将空视图推到堆栈上,并自动给您一个后退按钮。推视图控制器之后的大部分代码看起来都不可靠
-(void)aboutButtonPressed {
AboutViewController *aboutView =[[AboutViewController **alloc**] initWithNibName:@"About" bundle:nil];
[self.navigationController pushViewController:aboutView animated:YES];
[aboutView release];
}
这至少会将空视图推到堆栈上,并自动为您提供一个后退按钮。我删除了后退按钮代码,现在它看起来像您拥有的+一个[self.view addSubview:aboutView.view];因此,视图实际上会弹出。。。但它仍然不能像预期的那样工作。添加一张图片,在视觉上对正在发生的事情有一点了解。@SalsaSalsa好的,现在我看到问题了。你有AboutViewController吗?@salsalsa-你应该有一个AboutViewController,可以创建并推送到堆栈上,而不是一个新的UINavigationController。那是不可能的sense@Willcodejavaforfood是的,我有一个AboutViewController,但它不是NavigationViewController。。。如何将其转换为一个?我删除了后退按钮代码,现在它看起来像您拥有的+a[self.view addSubview:aboutView.view];因此,视图实际上会弹出。。。但它仍然不能像预期的那样工作。添加一张图片,在视觉上对正在发生的事情有一点了解。@SalsaSalsa好的,现在我看到问题了。你有AboutViewController吗?@salsalsa-你应该有一个AboutViewController,可以创建并推送到堆栈上,而不是一个新的UINavigationController。那是不可能的sense@Willcodejavaforfood是的,我有一个AboutViewController,但它不是NavigationViewController。。。我怎么把它变成一个?