代码之家  ›  专栏  ›  技术社区  ›  Dutchie432

iPhone SDK-导航控制器pushViewController-无响应

  •  0
  • Dutchie432  · 技术社区  · 17 年前

    我有一个视图,它有一个navigationController,有两个按钮,开始(基本上是一个登录按钮)和设置。单击“设置”时,将显示“设置”视图,并按计划取消。我可以单击“设置”,然后多次单击“上一步”,而不会导致任何崩溃。好的

    问题是,一旦我从登录按钮切换到注销按钮再切换到登录按钮,设置按钮就会停止工作。SHOWSETTINGS方法会触发并运行-不会发生错误-但不会显示视图。

    任何帮助都将不胜感激!!

    -(void)showLoginButtons{
        self.navigationItem.rightBarButtonItem=[[UIBarButtonItem alloc] initWithTitle:@"Settings" style:UIBarButtonItemStylePlain target:self action:@selector(showSettings)];
        self.navigationItem.leftBarButtonItem=[[UIBarButtonItem alloc] initWithTitle:@"Start" style:UIBarButtonItemStylePlain target:self action:@selector(tryConnection)];
    }
    
    -(void)showLogoffButtons{
        self.navigationItem.rightBarButtonItem=nil;
        self.navigationItem.leftBarButtonItem=[[UIBarButtonItem alloc] initWithTitle:@"Logoff" style:UIBarButtonItemStylePlain target:self action:@selector(resetConnectionAndScreen)];
    }
    
    -(void)showSettings{
        SettingsViewController *mySettingsViewController= [[SettingsViewController alloc] initWithNibName:@"SettingsViewController" bundle:nil];
        iPhone_PNPAppDelegate *mainDelegate = (iPhone_PNPAppDelegate *)[[UIApplication sharedApplication] delegate];
        mySettingsViewController.settings=mainDelegate.settings;
        [[self navigationController] pushViewController:mySettingsViewController animated:YES];
        [mySettingsViewController release];
    }
    
    1 回复  |  直到 17 年前
        1
  •  1
  •   Sean    17 年前

    您需要释放按钮,因为您正在分配它们。为此,我通常使用自动释放-尝试:

        -(void)showLoginButtons{
        self.navigationItem.rightBarButtonItem=[[[UIBarButtonItem alloc] initWithTitle:@"Settings" style:UIBarButtonItemStylePlain target:self action:@selector(showSettings)] autorelease];
        self.navigationItem.leftBarButtonItem=[[[UIBarButtonItem alloc] initWithTitle:@"Start" style:UIBarButtonItemStylePlain target:self action:@selector(tryConnection)] autorelease];
    }
    

    在showLogoffButtons方法中也执行同样的操作。