0

START (基本的にはログイン ボタン) と SETTINGS の 2 つのボタンを持つ navigationController を持つビューがあります。[設定] をクリックすると、設定ビューが表示され、計画どおりに閉じます。設定をクリックしてから、クラッシュすることなく何度もクリックすることができます。良い。

ここで、ユーザーが [開始] をクリックすると、navController で SHOWLOGOFFBUTTONS メソッドを呼び出して、ビューの上部に表示されるボタンを変更します。navBar には LOGOFF ボタンしかありません。そのボタンがクリックされると、SHOWLOGINBUTTONS を呼び出して、ユーザーが以前と同じログイン ボタンを持つようにし、SETTINGS と START (ログイン) に再度アクセスできるようにします。

問題は、LOGIN ボタンから LOGOFF ボタン、LOGIN BUTTONS への「ボタン切り替え」を行うと、SETTINGS ボタンが機能しなくなることです。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];
}
4

1 に答える 1

1

ボタンを割り当てるため、ボタンを離す必要があります。このために、私は通常自動リリースを使用します-試してみてください:

    -(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メソッドでも同じことを行います。

于 2009-04-28T14:24:59.263 に答える