登录视图后的SWRevealViewController

时间:2016-02-13 04:14:01

标签: ios objective-c iphone swrevealviewcontroller

我有一个具有登录视图的应用程序,然后在登录成功后我想要一个带侧边菜单的视图。 我正在使用SWRevealViewController制作幻灯片菜单。 但正如我所说的问题是登录视图将是第一个不是SWRevealViewController的视图。 我尝试在prepareForSegue方法中执行以下操作。

SWRevealViewController *revealViewController;
[revealViewController initWithRearViewController: [self.storyboard instantiateViewControllerWithIdentifier:@"MenuTableViewCell"]frontViewController:[self.storyboard instantiateViewControllerWithIdentifier:@"HomeViewController"]];

这不起作用。这是我在prepareForSegue方法中唯一的代码,我删除了if语句因为我在loginview中只有一个segue所以我想我不需要IF。 我应该从故事板中删除SWRevealViewController吗?或者将登录视图中的segue设为SWRevealViewController 我不知道该怎么办。 对于在视图中使用SWRevealViewController而不是第一个视图的情况,没有任何解释。 我正在为iOS构建这个应用程序,用于iPhone的目标c。 请帮忙。 感谢。

1 个答案:

答案 0 :(得分:3)

你应该像这样做你的故事板层次结构。

  • 拖动 ViewController 并将类更改为 SWRevealViewController。
  • NavigationController 中拖动 ViewController 嵌入式。将类名更改为 LoginViewController
  • NavigationController的情节提要ID更改为“LoginNavigationController”。

  • 将名为 sw_front 的新自定义segue从SWRevealViewController分配给NavigationController,并将segue类更改为 SWRevealViewControllerSegueSetController。

  • 将具有 TableView 的控制器拖动为侧视图的 MenuViewController 子视图。

  • 将SWRevealViewController中名为 sw_rear 的新自定义segue分配给MenuViewController,并将segue类更改为 SWRevealViewControllerSegueSetController。

  • 现在拖动嵌入 NavigationController 中的名为 HomeViewController 的ViewController,并指定标识为“ Home ”的自定义segue和带<的类强> SWRevealViewControllerSeguePushController。

  • 将NavigationController的故事板ID更改为“HomeNavigationController”。

这应该是故事板中的设置。

Storyboard structure

现在这里是编码部分:

In SWRevealViewController.m

- (void)viewDidLoad{

 [super viewDidLoad];

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(userSignedInSuccessfully) name:kUserSignedInNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(userSignOutSuccessfully) name:kUserSignedOutNotification object:nil];

  // this flag should be maintained in user defaults
  if(iSUserSignedIn){

     //Show Home page if user is already signed in
     [self showHomeScreen];
  }
}

#pragma mark - Show Home screen

-(void)showHomeScreen
{
  UINavigationController *navigation = [[UIStoryboard storyboardWithName:kStoryboardName bundle:nil] instantiateViewControllerWithIdentifier:@"HomeNavigationController"];

 [self setFrontViewController:navigation];
 [self setFrontViewPosition:FrontViewPositionLeft];
}

-(void)showLoginScreen{

  UINavigationController *navigation = (UINavigationController *)[[UIStoryboard storyboardWithName:kStoryboardName bundle:nil] instantiateViewControllerWithIdentifier:@"LoginNavigationController"];

  [self setFrontViewController:navigation];
  [self setFrontViewPosition:FrontViewPositionLeft];
}

现在,当用户在用户默认设置中首先保存标记 iSUserSignedIn 并发布此通知时。

//Post notification for successful sign in
[[NSNotificationCenter defaultCenter] postNotificationName:kUserSignedInNotification object:nil];

当用户将设置标志 iSUserSignedIn 注销为nil并发布此通知时。

//Post notification for successful sign out
[[NSNotificationCenter defaultCenter] postNotificationName:kUserSignedOutNotification object:nil];
相关问题