按 UIButton 将新视图推送到导航堆栈上

发布于 2024-10-06 20:30:35 字数 1253 浏览 2 评论 0原文

我目前有一个带有附加视图的窗口,其中包含三个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

秉烛思 2024-10-13 20:30:35

pushViewController 之后的大部分代码看起来都很危险。

-(void)aboutButtonPressed {
    AboutViewController *aboutView =[[AboutViewController **alloc**] initWithNibName:@"About" bundle:nil];
    [self.navigationController pushViewController:aboutView animated:YES];
    [aboutView release];
}

这至少应该将您的空视图推入堆栈并自动为您提供后退按钮。

Most of the code after pushViewController looks dodgy.

-(void)aboutButtonPressed {
    AboutViewController *aboutView =[[AboutViewController **alloc**] initWithNibName:@"About" bundle:nil];
    [self.navigationController pushViewController:aboutView animated:YES];
    [aboutView release];
}

That should at least push your empty view onto the stack and give you a back button automatically.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文