0

登录后我有登录屏幕,我正在推送到 HomeViewController。在 HomeViewController 上,我有一个“设置”按钮,按下它我正在呈现“SettingViewController”,现在在 settingViewController 上,我有一个用于注销的按钮。现在,当用户按下注销时,它应该在 LoginScreen 上弹出ToRootViewController.ie,但它没有完成。有什么建议么。这是我的代码。

登录时

-(void)login_Success
{
HomeViewController *homeView = [[HomeViewController alloc]init];
[[self navigationController]pushViewController:homeView animated:YES];
}

在主页呈现设置屏幕上

- (IBAction)btn_setting_Click:(id)sender
{
SettingsViewController *settingsViewController = [[SettingsViewController alloc]init];
[self presentModalViewController:settingsViewController animated:YES];  
}

在设置屏幕注销按下

- (IBAction)btnLogout_Click:(id)sender
 {
[appDelegate closeSession];
[self dismissModalViewControllerAnimated:NO];
 [[[self parentViewController]navigationController] popToRootViewControllerAnimated:YES];
 }

按注销时,这不会弹出到登录屏幕。有什么建议么。

4

3 回答 3

4

首先在 AppDelegate 中定义方法,如下所示:

-(void)logoutNav
{
    [self.navigationController popToRootViewControllerAnimated:YES];
}

然后在 SettingViewController 尝试以下代码

- (IBAction)btnLogout_Click:(id)sender
 {
    [self dismissModalViewControllerAnimated:NO];
    [((AppDelegate *)[[UIApplication sharedApplication] delegate]) logoutNav];
 }
于 2013-03-09T06:05:46.077 回答
0

您已经在两者之间展示了您的视图控制器。所以在下一个视图中弹出将不可用。甚至对于 rootViewController 也不行。

您需要关闭视图,然后弹出到上一个视图

享受编程!!

于 2013-03-09T05:41:52.243 回答
0
- (IBAction)btnLogout_Click:(id)sender
{
   [appDelegate closeSession];
   [self dismissModalViewControllerAnimated:NO];
   [[self.view.window.homeView navigationController] popToRootViewControllerAnimated:YES];
}

我不确定,但试试这个

编辑

使用委托尝试像这样实现

设置视图控制器.h

@protocol SettingsViewControllerDelegate
    -(void)logOut;
@end
...
@property(nonatomic, assign) id<SettingsViewControllerDelegate> delegate;

设置视图控制器.m

@synthesize @delegate;

- (IBAction)btnLogout_Click:(id)sender
{
    [appDelegate closeSession];
    [self dismissModalViewControllerAnimated:NO];
    [self.delegate logOut];
}

HomeViewController.h

#import "SettingViewController.h"
@interface HomeViewController : UIViewController <SettingsViewControllerDelegate>

主视图控制器.m

- (IBAction)btn_setting_Click:(id)sender
{
    SettingsViewController *settingsViewController = [[SettingsViewController alloc]init];
    settingsViewController.delegate = self
    [self presentModalViewController:settingsViewController animated:YES];  
}

-(void)logout
{
    [[self navigationController] popToRootViewControllerAnimated:YES];
}
于 2013-03-09T05:47:51.537 回答