App organization and UISplitViewController - ipad

I have a problem with my app organization.
I want an home view with four buttons. Each one pushing the view to a splitView.
So in my home view, I do not want any masterView displayed, ether in portrait or landscape mode.
But in my four next views, I want the masterView displayed at any time and I want to be able to have a back button to return to the home view.
My question is how do I achieve such a thing ?
Do I have to create my home View as the rootViewController of the app and then create one splitView per button. Then create a back button to dismiss the splitView.
Do I have to create one single splitView and play around with the master view display. I can't figure out how to hide my master class in portrait mode on certain views and show it on other views.

A UISplitViewController has to be the root view controller.
So you would start your app with a homeViewController that contains four buttons, each of which would tell your app delegate to remove the home view controller from root and create a splitViewController and make that the root.
Obviously to go back you would need a button on your splitViewController that would tell the app delegate to remove the splitViewController and replace with the newly loaded homeViewController.
an example of getting a viewController from a storyboard and attaching it to the window
window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
UIViewController *homeViewController = [mainStoryboard instantiateViewControllerWithIdentifier:#"HomeViewController"];
[window addSubview:homeViewController.view];
[window makeKeyAndVisible];

Related

iOS slide-menu - Objective-c

In my project I have existing side menu i.e swrevealviewcontrtoller to display right side menu.It is working correctly. I want to add second right menu in between the project using slideNavigationController. This is the screen shot of my storyboard. I can not touch existing base code and Before login page I want to add slideNavigationController to display another right sidemenubar.
i.e not my root view controller for that I referred these two links.SlideNavigationController,Solution for making rootviewcontroller
StoryBoard Image
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:#"Main" bundle: nil];
LoginViewController *loginView = (LoginViewController*)[mainStoryboard instantiateViewControllerWithIdentifier: #"Login"];
[loginView setModalPresentationStyle:UIModalTransitionStyleCrossDissolve];
SlideNavigationController * slideNavCtl = [[SlideNavigationController alloc] initWithRootViewController:loginView];
[self.window setRootViewController:slideNavCtl];
It is taking LoginViewController as root view controller.
As we are using SwrevealViewController at the first it contains modal segue so I am not able to display the right menu in login view controller. After adding that code in app delegate I am able to display right menu in loginpage but login page is the rootview but I want splash screen as a rootViewController. Using SlideNavigationController I want to display another right menu in login .

Swift iOS is it okay to stack 5 and more view controllers

I wonder if it's okay to stack 5+ view controllers in an app?
My problem is that I don't know how I can reset/remove old VC's and make a new one the root VC.
My app looks like this
navigation controller -> table view -> menu (modal segue) -> login screen (modal segue) -> account page (push segue) -> table view users images (push segue) -> user image details page (push segue)
The app doesn't crash but there is a lot of VC's stacked when entering the image details page.
Or can I somehow remove table view / menu / login screen from navigation and memory stack when entering account VC? So that account VC becomes root VC.
This completely depends on requirement of application flow and memory used by controllers. If you think you are going back to previous pages and process in those classed doesn't pile up memory heap. Then those may remain in stack. Otherwise make sure you keep removing viewControllers from stack.
In your case, I believe you don't really need login/registration page that frequently. So I will suggest change apps rootViewController to homeView after you logged in. And in case of logout change rootView again.
Edit: Here is how to change rootViewController
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:[NSBundle mainBundle]];
UINavigationController *rootViewController = nil;
if (condition) {
rootViewController = [storyboard instantiateViewControllerWithIdentifier:#"firstViewController"];
}else{
rootViewController = [storyboard instantiateViewControllerWithIdentifier:#"secondViewController"];
}
_appDelegate.window.rootViewController = rootViewController;
If you have view controllers on stack, that you never gonna use again, you can do this:
NSArray * old = self.navigationController.viewControllers;
NSArray * importantVCs = #[old[0], [old lastObject]]; //leave only root and top vc
[self.navigationController setViewControllers:importantVCs];
First item in array will be the new root view controller.

Jump to Uiviewcontroller on handling push in storyboard

I am handling push on alert to jump/open a view in story board like this from delegate
UIStoryboard * storyboard = [UIStoryboard storyboardWithName:#"Main_iphone4" bundle:nil];
ChatViewController *scvc = (ChatViewController *)[storyboard instantiateViewControllerWithIdentifier:#"ChatViewController"];
[self.window.rootViewController presentViewController:scvc animated:YES completion:nil];//not working show nothing while it works to jump using simple xib views.
and if i use
self.window.rootViewController =scvc;//it works but i need to get back on back button which causes it to get back in blank screen.
How to jump to a view controller using storyboard on handling push from delegate.
NOTE: The jump view have a back button,which need to dismiss the view too.
NOTE APP IS NOT NAVIGATION BASED

addSubview don't display toolbar top and bottom

I have something like that :
(1) NavigationController --> (2) UITableViewController --> (3 afted clicked in a cell) UIViewController
So when I receive a push notification, I want to redirect in the view controller ( which display a message )
I'm doing something like :
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:#"Main" bundle: nil];
_messageConsult = (MessageConsultDetailViewController*)[mainStoryboard instantiateViewControllerWithIdentifier: #"seeMoreView"];
_messageConsult.idMessage = [[userInfo objectForKey:#"aps"] objectForKey:#"id_message"];
_messageConsult.navigationController.toolbarHidden = NO;
self.window.rootViewController = _messageConsult;
[self.window addSubview:_messageConsult.view];
[self.window makeKeyAndVisible];
So it display the view well, but without any top/bottom bar. Althought when i'm displaying the view directly from the UITableViewCell, it works
Someone can give me some advice to this problem ?
You don't see it because you're instantiating a new instance of MessageConsultDetailViewController and making that your window's root view controller -- that means, it will be the only view controller in the hierarchy, and the navigation controller(with its navigation and tool bars)and table view controller will be deallocated if you don't have any strong pointers to them. The correct way to display that controller would be to do a push from the table view controller.
By the way, when you make a controller the window's root view controller, you shouldn't also add its view as a subview to the window -- that's already done when you make it the root view controller.

Setting First view controller in App Delegate

I am developing an iOS app and using storyboards. In my storyboard, I had set a view controller as the initial view controller. Everything working fine.
Now I have to write some login in app delegate to decide which view controller to show at the beginning because this depends on how far the user is in the login process.
So, I removed the initial view controller mark from my storyboard and removed the storyboard setting from my plist file.
Now, in the app delegate I have this code -
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:[NSBundle mainBundle]];
UIViewController *initialViewController = [storyboard instantiateViewControllerWithIdentifier:[XYZUtils getStartScreenViewController]];
XYZStartScreenViewController *startScreenViewController = (XYZStartScreenViewController *)initialViewController;
[self.window addSubview:startScreenViewController.view];
[self.window setRootViewController:startScreenViewController];
[self.window setBackgroundColor:[UIColor whiteColor]];
[self.window makeKeyAndVisible];
This does not display the view controller - I am just getting a black screen and no error messages. On using breakpoints to walk through the above code, there is no error. The view controller is being instantiated but it is not getting displayed.
Am I missing something here?
Read this post..
It is better you make an empty view controller and mark that as initial view controller
And do all login process in that view controller's viewDidLoad method.
Linking a new viewcontroller to Storyboard?
For some reason, when you deselect the initial view controller setting in the storyboard, then your app will not get a UIWindow setup in didFinishLaunching.
So, what you should so is instantiate your own window there; just add this to the beginning of your application didFinishLaunchingWithOptions method:
UIWindow* window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
I think this solution is perfectly fine, but a "cleaner" one since you are using the storyboard, is having some sort of "LoginManagerViewController" as your initial view controller with the responsibility of handling where to do next based on how far the user is in the login process.

Resources