我想创建一个标题为“配置文件”的 tabBarController,如果用户未登录,它会触发登录流程,如果未登录,则拉起某个视图控制器。我不可能是世界上唯一一个不需要类似东西的人。我尝试了以下类似的方法。
@implementation ProtectedViewController
//...
- (void)viewDidLoad
{
[super viewDidLoad];
if (FBSession.activeSession.state == FBSessionStateCreatedTokenLoaded) {
[self presentViewController: self.targetViewController animated: NO completion: nil];
} else {
AppDelegate* appDelegate = [[UIApplication sharedApplication] delegate];
[appDelegate showLoginView];
}
}
+ (ProtectedViewController*)protectedControllerFor:(UIViewController*)viewController
{
ProtectedViewController* protectedViewController = [[ProtectedViewController alloc] initWithNibName: nil bundle: nil];
protectedViewController.targetViewController = viewController;
return protectedViewController;
}
//...
someTabBarController.viewControllers = [feedViewController, [ProtectedViewController protectedControllerFor: newPostController];
这感觉很笨拙(并且还没有真正起作用)。这通常是如何完成的?