NavigationController 未弹出“后退按钮上的推送视图”

发布于 2024-08-29 17:46:40 字数 2435 浏览 4 评论 0原文

有了一个简单的导航控制器(启动基于导航的应用程序项目),我使用 XIB 文件创建了一个新视图。

在我的 HomeViewController 上(主屏幕上的所有选项都是 UIButton 的)我有:

@implementation HomeViewController

-(IBAction) optionChoosed:(UIButton *)button
{
    NSString *msg = [NSString stringWithFormat:@"Button: %d", button.tag];
    UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"Hi" message:msg delegate:nil cancelButtonTitle:@"Go away" otherButtonTitles:nil];
    
    switch (button.tag) {
        case 13:
            // Simple Search
            [self loadSimpleSearch]; break;
            
        default:
            [alert show];           
            break;
    }
    [alert release];
}

-(void)loadSimpleSearch
{
    SimpleSearchViewController *controller = 
        [[SimpleSearchViewController alloc] initWithNibName:@"SimpleSearchViewController" bundle:nil];
    
    [self.navigationController pushViewController:controller animated:YES];
    [controller release];
}

女巫工作得很好!

它将视图推入堆栈的前面!

现在,因为在我的第二个视图 SimpleSearchViewController 我有 self.title = @"myTitle"; 我在导航栏中获得了标题以及后退按钮(因为我在 < code>HomeViewController)

我以为 NavigationViewController 会处理当前视图的弹出,但事实并非如此。

我需要做什么才能弹出SimpleSearchViewController

我在哪里使用 [self.navigationController popViewControllerAnimated:YES];

因为视图继续在那里,并且 ViewDidUnload 永远不会被调用。

我的想法是,这应该在第一个 ViewController,即 HomeViewController 中处理,但我不知道应该挂钩的方法是什么,我阅读了文档,但无法弄清楚: -/

非常感谢任何帮助,谢谢

HomeViewController

替代文本 http://cl.ly/ XNS/Screen_shot_2010-04-21_at_22.38.51.png

SimpleSearchViewController

替代文本 http://cl.ly/YDw/Screen_shot_2010-04-21_at_22.40.00.png

SimpleSearchViewController 按下后退按钮后

替代文本 http://cl.ly/XLO/Screen_shot_2010-04-21_at_22。 40.21.png


添加评论中的图像,询问 HomeViewController 是否作为 NavigationViewController 的根控制器

alt text

Having a simple Navigation Controller in place (starting the Navigation Based Application project) I created a new View with a XIB file.

on my HomeViewController (Home screen with all options as UIButton's I have:

@implementation HomeViewController

-(IBAction) optionChoosed:(UIButton *)button
{
    NSString *msg = [NSString stringWithFormat:@"Button: %d", button.tag];
    UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"Hi" message:msg delegate:nil cancelButtonTitle:@"Go away" otherButtonTitles:nil];
    
    switch (button.tag) {
        case 13:
            // Simple Search
            [self loadSimpleSearch]; break;
            
        default:
            [alert show];           
            break;
    }
    [alert release];
}

-(void)loadSimpleSearch
{
    SimpleSearchViewController *controller = 
        [[SimpleSearchViewController alloc] initWithNibName:@"SimpleSearchViewController" bundle:nil];
    
    [self.navigationController pushViewController:controller animated:YES];
    [controller release];
}

witch works great!

it Pushes the View into the front of the stack!

Now, because in my 2nd view SimpleSearchViewController I have self.title = @"myTitle"; I get the Title in the NavigationBar as well the back button (as I have the same setting on the HomeViewController)

I thought that the NavigationViewController would handle the pop of the current view, but it does not.

What do I have to do, to pop the SimpleSearchViewController?

Where do I use [self.navigationController popViewControllerAnimated:YES];

as the view continues there, and ViewDidUnload is never called.

My idea was that this should be handle in the first ViewController, the HomeViewController but I have no idea what is the method I should hook to, and I read the documentation and I can't figure it out :-/

Any help is greatly appreciated, thank you.

HomeViewController

alt text http://cl.ly/XNS/Screen_shot_2010-04-21_at_22.38.51.png

SimpleSearchViewController

alt text http://cl.ly/YDw/Screen_shot_2010-04-21_at_22.40.00.png

SimpleSearchViewController after pressing the Back button

alt text http://cl.ly/XLO/Screen_shot_2010-04-21_at_22.40.21.png


To add the image from a comment that asks if HomeViewController as the root controller for the NavigationViewController

alt text

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

递刀给你 2024-09-05 17:46:40

不确定这是否有帮助,但是在代码中实现 navigationItem 时,如果您不调用 super,则弹出功能将不会出现

-(UINavigationItem*) navigationItem
{
    UINavigationItem* item = [super navigationItem];
    item.title = @"search";
    return item;
}

Not sure if this helps but when implementing navigationItem in code, if you don't call the super the popping functionality will not be present

-(UINavigationItem*) navigationItem
{
    UINavigationItem* item = [super navigationItem];
    item.title = @"search";
    return item;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文