按 UIButton 将新视图推送到导航堆栈上
我目前有一个带有附加视图的窗口,其中包含三个 UIButton。当用户按下按钮时,我希望使用导航控制器将视图更改为新视图。
现在,我的 about 按钮的编码如下:
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 文件中当前没有任何内容。
现在解决问题...当按下按钮时,顶部导航栏会出现在顶部,但不是像我编码的那样以动画方式显示。它只是弹出。此外,没有后退按钮可以返回到带有按钮的视图。我做错了什么?如果这还不够清楚,我可以提供更多代码或详细信息。
编辑:这是一张图片,可以更好地理解正在发生的事情。
单击“关于”按钮后:
http://dl.dropbox.com/u/1481176/Screen%20shot%202010-12-09%20at%2011.28.40%20AM.png
编辑2:删除了后退按钮的一些不稳定代码不应该在那里。
I currently have a window with a view attached that has three UIButtons. When the user presses a button, I would like the view to change to a new view using a NavigationController.
So right now I have the about button coded like so:
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];
And for the action function:
-(void)aboutButtonPressed {
UINavigationController *aboutView =[[UINavigationControlleralloc] initWithNibName:@"About" bundle:nil];
[self.navigationController pushViewController:aboutView animated:YES];
[self.view addSubview:aboutView.view];
[aboutView release];
}
The About.xib file currently has nothing in it.
Now on to the problem... When the button is pressed a top navigation bar appears at the top but not in the animated sense like I have it coded. It just pops up. Also there is no back button to return to the view with the buttons on them. What am I doing wrong? I can provide more code or details if this is not clear enough.
Edit: Here is a picture to better understand what is happening.
After clicking the about button:
http://dl.dropbox.com/u/1481176/Screen%20shot%202010-12-09%20at%2011.28.40%20AM.png
Edit 2: Removed some wonky code for a back button that shouldn't of been there.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
pushViewController 之后的大部分代码看起来都很危险。
这至少应该将您的空视图推入堆栈并自动为您提供后退按钮。
Most of the code after pushViewController looks dodgy.
That should at least push your empty view onto the stack and give you a back button automatically.