How to use SWRevealViewController with iPad SplitViewController - ios

Hi I am using storyboard for my iPad app. How can I add SWRevealViewController to my app. I want to add slide view to my master view controller. Can any body please suggest me. I am loading my splitView using the following code in AppDelegate.h
UISplitViewController *splitViewController = (UISplitViewController *)self.window.rootViewController;
UINavigationController *navigationController = [splitViewController.viewControllers lastObject];
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard_iPad" bundle:nil];
DetailViewController *rootViewController = [storyboard instantiateViewControllerWithIdentifier:#"CouponDetailRoot"];

Just make the Master View Controller the sw_front view of the SWRevealViewController. Then, if you want the detail view to be collapsed so only the master view shows up at first, create a class like this and assign it to the Master View Controller in storyboard:
import UIKit
class GlobalSplitViewController: UISplitViewController, UISplitViewControllerDelegate {
override func viewDidLoad() {
super.viewDidLoad()
self.delegate = self
}
func splitViewController(_ splitViewController: UISplitViewController, collapseSecondary secondaryViewController:UIViewController, onto primaryViewController:UIViewController) -> Bool {
return true
}
}

Related

How to add my custom UIViewController in react native App

I want to implement Face detection in react native. I want to add CameraViewController Demo in react native. CameraView controller source code is here: https://github.com/googlesamples/ios-vision/blob/master/FaceDetectorDemo/FaceDetector/CameraViewController.m
import Foundation
#objc(SampleViewManager)
class SampleViewManager : RCTViewManager {
override func view() -> UIView! {
// UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Sample" bundle: nil];
// //
// UIViewController *vc = [storyboard instantiateInitialViewController];
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateInitialViewController()!
return vc.view;
}
}
but error occured:Could not load the "Camera" image referenced from a nib in the bundle with identifier
kindly help me how to implement Face detection in react native.

How to represent a startup screen in Storyboards

Right now I have a MainViewController which is embedded in a UINavigationController so the navigation controller is set as initial view controller.
What I want is first time the app starts and only then to show a StartupViewController. But I am not sure how to represent this in my storyboard.
Should this be set as initial view controller if the app starts the first time, if not the navigation controller should be set.
What I tried is to show StartupViewController in MainViewController::viewDidLoad(), but its not working how I wanted too.
Anyone know what is the right approach to do this ?
Hello this code may be helpfull for you :
// MARK: - Application Supporting Funcations -
func loadFirstViewController(viewController: String)
{
// for loading first view Controller
let storyBoard = appDelegate.AppStoryBoard()
/////////////////////////Add Navigation Controller and set Root View Controller///////////////////////////////////////
let object = storyBoard.instantiateViewControllerWithIdentifier(viewController) // for prelogin navigation
self.navigationController = UINavigationController(rootViewController: object)
self.navigationController?.navigationBar.hidden = true
self.loadNavigationControllerToWindow()
}
func loadNavigationControllerToWindow()
{
if self.window == nil
{
self.window = UIWindow(frame: UIScreen.mainScreen().bounds)
}
// for loading root view
self.window!.rootViewController = self.navigationController!
self.window!.makeKeyAndVisible()
}
call this function in didFinishLaunchingWithOptions
if((NSUserDefaults.standardUserDefaults().valueForKey("isFirstTime") != nil))
{
self.loadFirstViewController("LoginVC") // for loading first view controller
}
else
{
self.loadFirstViewController("WelcomeVC") // for loading first view controller
}
put this after you go in second controler viewDidLoad
if((NSUserDefaults.standardUserDefaults().valueForKey("isFirstTime") == nil))
{
NSUserDefaults.standardUserDefaults().setValue("1", forKey: "isFirstTime")
}
This is how I acheived in my app.
Add this in appdelegate applicationdidfinishlaunching.
NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
if (![defaults boolForKey:#"FirstTime"])
{
//NSLog(#"Enter First Time ");
UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:#"Main" bundle:[NSBundle mainBundle]];
StartupViewController * firstViewController = [storyBoard instantiateViewControllerWithIdentifier:#"StartupViewController"];//AskAndAnswerViewId RegisterViewId TagViewId HelpViewId
self.navigationController=[[UINavigationController alloc]initWithRootViewController:firstViewController];
self.window.rootViewController = self.navigationController;
[self.navigationController setNavigationBarHidden:YES];
}
else
{
//NSLog(#"not First Time");
UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:#"Main" bundle:[NSBundle mainBundle]];
HelpViewController *mainviewcontroller = [storyBoard instantiateViewControllerWithIdentifier:#"AskAndAnswerViewId"];
self.navigationController=[[UINavigationController alloc]initWithRootViewController:mainviewcontroller];
self.window.rootViewController = self.navigationController;
[self.navigationController setNavigationBarHidden:YES];
}
Once you reached in Mainviewcontroller change the userdefault value for FirstTime to "NO".
I understand your Question ,
In AppDelegate try to set rootViewController ,
I have store data in the NSUserDefault if user came first time
And try to set rootViewController once he visit first time.
In below Example I have navigate user to Login screen/Home screen
let str = userDefaults.objectForKey("firstTime")
{}else{}
Please don't forget to give identifier to your view controller StartupViewController
-> user interaction enable in StartupViewController
if (UserDefaults.standard.string(forKey: "keepUsername") != nil) {
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewController(withIdentifier: "Revealview")
self.present(vc, animated: false, completion: nil)
}
else
{
let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil)
let nextViewController = storyBoard.instantiateViewController(withIdentifier: "loginview") as! loginview
self.present(nextViewController, animated:true, completion:nil)
}

Programmatically switch view controller to show views in Tab Bar Controller

I am trying to figure out how I can programmatically switch the views from one view controller to a first view controller in a Tab bar controller when I press a button.
Currently I have a view controller with three buttons. When I press a button I would like to then switch. This is the following code I have for this screen. It is called the second view controller.
import UIKit
class SecondViewController: UIViewController {
//Button Outlets
#IBOutlet var ButtonEndOfShift: UIButton!
#IBOutlet var ButtonMultiTimes: UIButton!
#IBOutlet var ButtonEndAndLunch: UIButton!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
//hides tab bar controller
self.tabBarController?.tabBar.hidden = true
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
//Changes screen for End Of Shift Button
#IBAction func ChangeNextViewLow(sender: AnyObject) {
self.performSegueWithIdentifier("segue", sender: nil)
}
//Changes screen for Lunch and End Of Shift Button
#IBAction func ChangeNextViewMedium(sender: UIButton) {
}
//Changes screen for Multiple Times button
#IBAction func ChangeNextViewHigh(sender: UIButton) {
}
}
I have added UITabBarController in Storyboard like below please see images.
Then i have written following functions for your help.
// For navigate to Tabbar Controller
#IBAction func btnClick () {
self.performSegueWithIdentifier("GoToTabBar", sender: nil)
}
// For switching between tabs
func switchTab (index : Int) {
self.tabbarController.selectedIndex = index
}
You can also set UITabBarController as your application RootViewController.
Implement Code For didFinishLaunchingWithOptions
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
firstViewController *firstTab = [[firstViewController alloc] initWithNibName:#"firstViewController" bundle:nil];
UINavigationController *navCntrl1 = [[UINavigationController alloc] initWithRootViewController:firstTab];
secViewController *secTab = [[firstViewController alloc] initWithNibName:#"secViewController" bundle:nil];
UINavigationController *navCntrl2 = [[UINavigationController alloc] initWithRootViewController:secTab];
thirdViewController *thirdTab = [[thirdViewController alloc] initWithNibName:#"thirdViewController" bundle:nil];
UINavigationController *navCntrl3 = [[UINavigationController alloc] initWithRootViewController:thirdTab];
UITabBarController *tabBarController = [[UITabBarController alloc] init];
tabBarController.viewControllers = #[navCntrl1, navCntrl2, navCntrl3];
[self.window setRootViewController:tabBarController];
[self.window makeKeyAndVisible];

Going directly to Main View controller for already logged in user

I have a loginViewController as my rootviewcontroller followed by the main screen and then other screens. My views follow push and pop approach. What I want is, if a user is already logged in my view should start from main screen else start from login screen, and if I logout from main screen it should go back to login screen and the push and pop structure should be maintained. I can achieve this using the modal transition, but I need to use push and pop approach, is this possible? Currently I have checked a already logged in condition in my appdelegate to set the rootview controller but it fails if I attempt to log out as its not present in my navigation controller stack.
if !alreadyLoggedin
{
let mainListVC = storyBoard.instantiateViewControllerWithIdentifier(“MainListViewController”)
self.window!.rootViewController = mainListVC
}
else
{
let loginVC = storyBoard.instantiateViewControllerWithIdentifier("ViewController")
self.window!.rootViewController = loginVC
}
It's basic use case, Please follow my steps.
In your story create navigation view controller with view controller.
Select navigation view controller as your initial view controller in storyboard.
Create three views controllers- InitialViewController, LoginViewController and MainViewController and set storyboard id for all view controllers.
Created sample project for you. Download link (https://www.dropbox.com/s/zk8x7ptg5mzmotk/test.zip?dl=0)
You need to use. AppDelegate
Objective C
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
if (![[NSUserDefaults standardUserDefaults] boolForKey:#"LoginStatus"]) {
UIStoryboard* storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
self.window.rootViewController = [storyboard instantiateViewControllerWithIdentifier:#"loginController"];
}else{
UIStoryboard* storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
self.window.rootViewController = [storyboard instantiateViewControllerWithIdentifier:#"RootView"];
}
}
SWIFT - i hope its correct
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: NSDictionary?) -> Bool {
//Using UserDefaults check already loggedin user or not
if (!someStatus) {
let storyboard = UIStoryboard(name: "MyStoryboardName", bundle: nil)
let vc = storyboard.instantiateViewControllerWithIdentifier("someViewController") as! UIViewController
self.presentViewController(vc, animated: true, completion: nil)
}else{
let storyboard = UIStoryboard(name: "MyStoryboardName", bundle: nil)
let vc = storyboard.instantiateViewControllerWithIdentifier("loginViewController") as! UIViewController
self.presentViewController(vc, animated: true, completion: nil)
}
}

Implementing SWRevealViewConroller Library (slide out menu) in multiple storyboards

I am trying to implement SWRevealViewController Library as given in VideoTutorial, I was successfully able to do that but I don't want everything on 1 storyboard, I want to break it down in 2 storyboards
AppDelegate Code:
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
storyboard = UIStoryboard(name: "MenuDrawer", bundle: nil)
initialViewController = storyboard.instantiateViewControllerWithIdentifier("SWRevealViewController") as! UIViewController
self.window?.rootViewController = initialViewController
self.window?.makeKeyAndVisible()
return true
}
Rightnow MenuDrawer storyboard has everything
SWRevealViewCOntroller
TableViewController
NavigationController
RootViewController
and below segues which are defined in Library:
segue1 (sw_rear) : between SWRevealViewController --> TableViewController
segue2 (sw_front) : between SWRevealViewController
--> NavigationController
now I want 3 and 4 in different storyboard. but when I move 3 and 4 to different storyboard how do I create segue 2 across storyboards
I am not really sure if I understand your problem but you can try this to retrive your second storyboard and load your navigationViewController from there.
let storyBoard : UIStoryboard = UIStoryboard(name: "SecondStoryBoard", bundle:nil)
let deleteViewController = storyBoard.instantiateViewControllerWithIdentifier("SecondNavigationController") as UINavigationController
as far as iknow, you don't need to push again the segue 2 on 3 and 4. what you need is refer the new view (3 and 4) on the segue 2. in Obj-c will be like that:
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
SWRevealViewController *view = [mainStoryboard instantiateViewControllerWithIdentifier:identifier];
[view setModalTransitionStyle:UIModalTransitionStyleCoverVertical];
[self.navigationController pushViewController:view animated:YES];
where "self" is the ViewController where segue 2 has been created.
i hope have answered your question.
Try This First Of All Make the other storyboard and add what you need then call the other storyboard in
AppDelegate Code:
func application(application: UIApplication,didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
var storyboard = UIStoryboard(name: "MenuDrawer", bundle: nil)
var storyboard1 = UIStoryboard(name: "NewStoryBoardName", bundle: nil)
var initialViewController = storyboard.instantiateViewControllerWithIdentifier("SWRevealViewController") as! UIViewController
var initialViewController1 = storyboard1.instantiateViewControllerWithIdentifier("SWRevealViewController") as! UIViewController
self.window?.rootViewController = [initialViewController,initialViewController1]
self.window?.makeKeyAndVisible()
return true
}
You can not create segues between storyboards using Interface Builder.
It is only possible programmatically, example:
let storyBoardTwo = UIStoryboard(name: "storyBoardTwo", bundle: nil)
// Pick a view controller using it's identifier string set in Interface Builder.
let myVC = storyBoardTwo.instantiateViewControllerWithIdentifier("aViewController") as! UIViewController // Or use more specific (custom) type
// Push it to the navigation controller
self.navigationController.pushViewController(myVC, animated: true)
pushViewControllerwill simply put the myVC on top. This code is what a segue will end up doing. You can put this code anywhere in an existing ViewController, on a button tap IBAction or where ever needed.
If the pushed ViewController have any segues (from Storyboard or code) they will still work, as expected.
This of course works if you would want to programmatically load ViewController from one and the same Storyboard as well.

Resources