如果注册或登录成功,我按照parse.com教程了解如何实现login + register + segue到主控制器。这很美。
然后我想使用SWRevealViewController实现侧面导航。我在此关注了APPCODA链接,并且仅在" SWRevealViewController"是初始视图控制器。
当我将我的解析登录控制器作为初始时,我无法从导航控制器中看到任何东西,即#SW; SWRevealViewController。"
如何解决这个问题,让我的登录/注册控制器成为初始控制器,并且在登录/注册成功时仍然能够拥有SWRevealViewController?
我将不胜感激任何帮助或指示。
下面是我的APPDelegate.m
#import "AppDelegate.h"
#import <Parse/Parse.h>
#import <GoogleMaps/GoogleMaps.h>
@interface AppDelegate ()
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
LoginView *lv = [[LoginView alloc]init];
SidebarViewController *sbvc = [[SidebarViewController alloc]init];
UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:lv];
UINavigationController *menuVC = [[UINavigationController alloc]initWithRootViewController:sbvc];
SWRevealViewController *revealController = [[SWRevealViewController alloc]initWithRearViewController:menuVC frontViewController:nav];
revealController.delegate = self;
self.menu = revealController;
self.window.rootViewController = self.menu;
[GMSServices provideAPIKey:@"XXXXXXXXXX"];
[Parse setApplicationId:@"XXXXXXXXXXXXX"
clientKey:@"XXXXXXXXXXXXX"];
[PFAnalytics trackAppOpenedWithLaunchOptions:launchOptions];
return YES;
}
答案 0 :(得分:3)
在具有用户会话的应用中,通常最好将登录/注册保持在与应用程序其余部分不同的视图层次结构中,并在存在活动会话时显示内部结构。您可以通过检查
来实现此目的[PFUser currentUser]
因为如果用户没有登录,它将返回nil
。
在AppDelegate中提供支票,如下所示:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// .. Rest of your initialization code
if ([PFUser currentUser]) {
// Let's pop them right to the home screen
[self showHomeScreen];
}
else {
// Present login vc
LoginView *lv = [[LoginView alloc] init];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:lv];
self.window.rootViewController = nav;
}
return YES;
}
- (void)showHomeScreen {
SidebarViewController *sbvc = [[SidebarViewController alloc] init];
UINavigationController *menuVC = [[UINavigationController alloc] initWithRootViewController:sbvc];
UIViewController *home = [[UIViewController alloc] init];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:home];
SWRevealViewController *revealController = [[SWRevealViewController alloc] initWithRearViewController:menuVC frontViewController:nav];
self.window.rootViewController = revealController;
}
然后,包括
- (void)showHomeScreen;
在AppDelegate.h
中,您可以在注册/登录成功后调用此方法:
AppDelegate *delegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
[delegate showHomeScreen];
答案 1 :(得分:2)
我只是想知道如何以编程方式从app delegate显示我的仪表板视图。使用SWRevealViewController&amp; swift 2.0:
在你的main.storyboard上,你必须识别菜单视图(我的意思不是导航控制器)我的右侧菜单,身份检查员 - &gt; identiy-&gt; storyboardID ='right2'。
我的左侧菜单,称为'rear2'。
对于我的前视图,在显示我的仪表板视图的导航视图控制器上,我将标识设置为“仪表板”
在你的appdelegate中,在我的函数'didFinishLaunchingWithOptions'下:
//this is your main.storyboard
let storyboard = UIStoryboard(name: "Main", bundle: nil)
//initialize your FRONT view controller, ie my dashboard view, mine is a UINavigationController, which then presents a table view , ie why i instantiate with a UINavigationController.
let frontviewcontroller = storyboard.instantiateViewControllerWithIdentifier("dashboard") as? UINavigationController
//initialize REAR View Controller- it is the LEFT hand menu.
let rearViewController = storyboard.instantiateViewControllerWithIdentifier("rear2") as? UITableViewController
//initialize RIGHT View Controller - it is your RIGHT hand menu.
let rightViewController = storyboard.instantiateViewControllerWithIdentifier("right2") as? UITableViewController
let mainRevealController = SWRevealViewController()
mainRevealController.frontViewController = frontviewcontroller
mainRevealController.rightViewController = rightViewController
mainRevealController.rearViewController = rearViewController
self.window!.rootViewController = mainRevealController
self.window?.makeKeyAndVisible()
希望它可以帮助别人。 谢谢 d。
答案 2 :(得分:0)
以下是我在用户登录后换出导航层次结构的方式:
+ (void)postSignInUICodeFromViewController:(UIViewController *)vc {
// Log in was successful
// Create new view controller
ViewController1 *v1 = [[ViewController1 alloc] init];
typeof(vc) weakVc = vc;
// This is a property that I have added to my
// custom UIViewController subclass. As you might
// guess, it's called in "viewDidAppear:"
v1.viewDidAppearCompletionBlock = ^{
// After pushing the new UI hierarchy into view,
// this will delete/remove the rest of the UI stack
weakVc.navigationController.viewControllers = @[v1];
};
// At this point (since the block above hasn't yet fired),
// you're pushing your new UI hierarchy ON TOP OF the login
// view controller
[vc.navigationController pushViewController:v1 animated:YES];
}
+ (void)postSignInUICodeFromViewController:(UIViewController *)vc {
// Log in was successful
// Create new UI hierarchy
ViewController1 *v1 = [[ViewController1 alloc] init];
NavViewController *nav1 = [[UINavController alloc] initWithRootViewController:v1];
ViewController1 *v2 = [[ViewController2 alloc] init];
NavViewController *nav2 = [[UINavController alloc] initWithRootViewController:v2];
ViewController1 *v3 = [[ViewController3 alloc] init];
NavViewController *nav3 = [[UINavController alloc] initWithRootViewController:v3];
ViewController1 *v4 = [[ViewController4 alloc] init];
NavViewController *nav4 = [[UINavController alloc] initWithRootViewController:v4];
TabBarViewController *tabBar = [[TabBarViewController alloc] init];
tabBar.viewControllers = @[nav1, nav2, nav3, nav4];
typeof(vc) weakVc = vc;
typeof(tabBar) weakTabBar = tabBar;
__weak NavViewController *navVc = (NavViewController *)weakVc.navigationController;
// This is a property that I have added to my
// custom UITabBarController subclass. As you might
// guess, it's called in "viewDidAppear:"
tabBar.viewDidAppearCompletionBlock = ^{
// After pushing the new UI hierarchy into view,
// this will delete/remove the rest of the UI stack
weakVc.navigationController.viewControllers = @[weakTabBar];
};
// At this point (since the block above hasn't yet fired),
// you're pushing your new UI hierarchy ON TOP OF the login
// view controller
[vc.navigationController pushViewController:tabBar animated:YES];
}
在这两个例子中,我组成了一个名为ViewController1
的新类。在UITabBarController
示例中,所有其余内容也由类名组成,仅用于说明目的。 您需要输入您的班级名称。
答案 3 :(得分:0)
好的,我明白了。在这里;
不是创建主视图控制器的segue,而是创建它到SWRevealViewController。我认为SW将该控制器设置为“sw_front”。只有通过PFUser将其作为segue才能使用。
答案 4 :(得分:0)
在登录ViewController 创建按钮操作。
你可以像这样设置。
@IBAction func btnLoginAction(_ sender: UIButton) {
let objAppDelegate = UIApplication.shared.delegate as! AppDelegate
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let rearViewController = storyboard.instantiateViewController(withIdentifier: "backTableVc") as? backTableVc
let frontViewController = storyboard.instantiateViewController(withIdentifier: "ViewController") as? ViewController
let naviRoot = UINavigationController(rootViewController: frontViewController!)
naviRoot.navigationBar.isHidden = true
let mainRevealController = SWRevealViewController()
mainRevealController.frontViewController = naviRoot
mainRevealController.rearViewController = rearViewController
UIView.transition(from: (objAppDelegate.window?.rootViewController!.view)!, to: mainRevealController.view, duration: 0.6, options: [.transitionCrossDissolve], completion: {
_ in
objAppDelegate.window?.rootViewController = mainRevealController
})
objAppDelegate.window?.makeKeyAndVisible()
}