【问题标题】:Switch from TabBarView back to Standard View从 TabBarView 切换回标准视图
【发布时间】:2010-12-03 15:58:13
【问题描述】:

我已经实现了一个您登录的应用程序,一旦您登录,它就会将您带到一个标签栏视图。但是,我想实现一个注销按钮,当用户按下按钮时,它会将他们带回登录视图。

我现在有以下代码,但它不起作用。 UIBarButton 被调用,因为它产生 NSLog 输出到 gdb。但是它不会切换视图。

在我看来,标签栏。

- (IBAction) logoutButtonPushed {
    NSLog(@"Yes, I was pushed");
    [self.appdelegate logout];
}

然后在我的应用委托中。

//  Logout and return to the welcome view
- (void) logout {


    [self.tabBarViewController.view removeFromSuperview];
    [window addSubview:self.welcomeViewController.view];
    [window bringSubviewToFront:self.welcomeViewController.view];

    [userModel logout];
}

只是为了好玩,这是我将标签栏放在前面的方法。

//  Switches to the tab bar view from either the welcome or registersuccess view
- (void) switchToTabBarView {

    [self.registerSuccessViewController.view removeFromSuperview];
    [self.welcomeViewController.view removeFromSuperview];
    [window addSubview:self.tabBarViewController.view];
    [window bringSubviewToFront:self.tabBarViewController.view];

}

欢迎任何帮助或改进我的代码的建议(我可能有很多不好的做法)。谢谢!

【问题讨论】:

    标签: iphone objective-c


    【解决方案1】:

    请参阅我对此question 的回答。

    您不应该使用self,因为它不会引用标签栏控制器。不要使用self,而是使用放置标签栏控制器的视图控制器实例

    AppDelegate.h

    YourViewController *yourViewControllerObj;
    @property(nonatomic,retain) YourViewController *yourViewControllerObj;
    

    AppDelegate.m

    @synthesize yourViewControllerObj;
    

    YourViewController.m 中,为您的AppDelegate 实例设置对象:

    - (void)viewDidLoad 
    {
        appDelegate.yourViewControllerObj = self;
        // Do whatever you want
    }
    

    然后在您的注销功能中

    - (IBAction) logoutButtonPushed {
      NSLog(@"Yes, I was pushed");
      loginScreen *loginScreenObj = [[loginScreen alloc] initWithNibName:@"loginScreen" bundle:[NSBundle mainBundle]];
      [appDelegate.yourViewControllerObj  presentModalViewController:loginScreenObj animated:YES];
      [loginScreenObj release];
    }
    

    【讨论】:

    • 感谢您对此进行扩展!
    • 那么我如何将标签栏放在首位呢?
    • 在主控制器中仅使用登录视图控制器..在另一个视图控制器中放置标签栏控制器..
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-30
    相关资源
    最近更新 更多