Show view from storyboard chain - objective-c

I have a chain in storyboard and I want to start (for example) second view when I have first launching app. I have some code, which only work in
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
method, if I put it in
- (void)viewDidLoad
method it's not work,
the code which show my other view is:
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
UIViewController *vc = [mainStoryboard instantiateViewControllerWithIdentifier:#"someId"];
[vc setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
How can I show view, which have place in chain in storyboard when app have first launching?

Try your code in
-(void)viewDidAppear:(BOOL)animated.
For further information on the iOS viewcontroller lifecycle head over to UIViewController class reference

If you are using a navigation controller, you can simply push the second view onto the navigation stack. If you are not using a navigation controller, then you could force a segue to the next view from the loading.

Related

Issue in moving from swrevealcontroller to new view controller in iOS?

I have a swrevealcontroller on my storyboard.I move to different view controller by passing selecting the view controller name in the table view.Now i am also showing a new table view when i tap on one of the item of tableview in swrevealcontroller.In select of new tableview item i want to show a new view controller which will not be part of the swrevealcontroller.But i am not able to show this.
I have tried this code but it does not show the back button when new view controller is shown.
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
UINavigationController *vc = (UINavigationController *)[storyboard instantiateViewControllerWithIdentifier:#"DetailController"];
[self presentViewController:vc animated:YES completion:nil];
Thanks in advance.
It's because presentViewController present a viewcontroller as a modal one. Secondly, even if you switch from presentViewController to pushviewcontroller an error will be thrown due to the fact that UINavigationController can not be pushed by another UINavigationController.

how to change current displaying uiview without using segues?

i want to change display to an UIViewController which has view controller at storyboard from an UIViewController class which hasn't got view controller at storyboard. There is no segue at storyboard for this...
Just like this:
In your AppDelegate.m do a quick setup:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
ViewController *sourceViewController = [[ViewController alloc] init];
UINavigationController * nav = [[UINavigationController alloc] initWithRootViewController:sourceViewController];
[self.window setRootViewController:nav];
return YES;
}
In above example replace ViewController class with your own class of sourceViewCntroller
- (IBAction) didPressMyButton {
NewViewController* newVC = [[[NewViewController alloc] init] autorelease];
[self.navigationController pushViewController:newVC animated:YES];
}
Connect this action to a button on storyboard or embed view change in any method. You will need to setup UINavigation controller first.
I'm not completely sure I understand what you're trying to do, but I think you are asking how to load a view controller from a storyboard, without using a segue, from a method in a view controller that wasn't loaded from the storyboard.
First, in your storyboard, select the view controller you want to load, and open the Identity Inspector. Set the Storyboard ID of the view controller. It looks like you want to load a MapViewController, so let's say you set the storyboard ID to map.
In your code, you can load the view controller like this:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
MapViewController *mapViewController = [storyboard instantiateViewControllerWithIdentifier:#"map"];
Once you have a reference to the view controller, you can set its properties or send it messages. You can then display it in whatever way you want - maybe by pushing it onto a navigation controller, or by presenting it, or by setting it as the root view controller of your window.

how to access the UITabBarController when its not the initial view?

I'm having problem with accessing my tabbarcontroller in the storyboard when its not the initial view. So basically there is an initial view in the storyboard which leads to the tabbarcontroller. I want to change the color of the tab but i dont have access to it! I know that it can be added to the delegate if its the initial view but in this case its not the initial view in the storyboard! I read somewhere that I have to override a method in the first view but there was no detail about it!
If you are in a viewcontroller in the storyboard then this code:
UIStoryboard *storyboard = self.storyboard;
UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:#"OtherViewController"];
Will get the other viewcontroller youw want and you could do things such as:
set yourself as delegate for it:
[(OtherViewController *)vc setDelegate:self];
display it:
[self presentViewController:vc animated:YES completion:nil];
I think you could use this to get the other viewcontroller and then access the tabbar from it.
Sorry if I misunderstood what you are trying to do.

How to presentModalViewController without dismiss the TabBarController

Hey guys i`m trying to present a modal view controller inside an application with a tab bar controller. The problem is, every time the new view is presented, it on top of my tab bar.
I need to keep my tab bar even when the view is presented. Like google maps application does with his toolbar at the bottom of the screen.
How can i do that?
Thank you
By default, a modal view controller is meant to take up the entire screen (on an iPhone/iPod, at least). Because of this, it covers whatever you have on screen at the time.
A view controller presented via modal segue is meant to live on its own. If you want to keep your Navigation and TabBar, then just use a push segue to present the new ViewController. Remember to use this kind of segue, your presenting controller needs to be part of a UINavigationController already.
Use this to push a ViewController. If it is a UINavigationController it will push its linked RootViewController by itsself.
Create a viewController to push: (Using Storyboard)
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard_iPhone" bundle:nil];
UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:#"LoginViewController"];
or (Using Code/Nibs)
LoginViewController *viewController = [[LoginViewController alloc] init]; //initWithNibNamed in case you are using nibs.
//in case you want to start a new Navigation: UINavigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
and push with:
[self.navigationController pushViewController:vc animated:true];
Also, if you are using Storyboards for the segues you can use this to do all the stuff. Remember to set the segue identifier.
[self performSegueWithIdentifier:#"pushLoginViewController" sender:self]; //Segue needs to exist and to be linked with the performing controller. Only use this if you need to trigger the segue with coder rather than an interface object.
- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:#"pushLiftDetail"]) {
[[segue.destinationViewController someMethod:]];
segue.destinationViewController.someProperty = x;
}
}
I think you'll need to add a UITabBar to the modal view and implement/duplicate the buttons and functionality that your main bar has. The essence of a modal window is it has total control until it is dismissed.
You might try putting your UITabBarController into a NavBarController, but I'm not certain that this will work.
UITabBarController -> NavBarController -> Modal View

Modal view after start app does not appear

Before the users can use my app the have to login. My idea was that after the app starts the login view appears modally.
Before iOS 5 I had it all working with .xib files. Now I want to convert the views to a Storyboard for overview and better use of the new functionalities.
The app works with a splitview controller. The problem is that the login view is loaded, but never appears.
I tried it in the app delegate and I made a class for the splitviewcontroller and tried to load it in the viewDidLoad.
Code:
- (void)viewDidLoad
{
[super viewDidLoad];
//load and push login
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
LoginViewController *loginViewController = [storyboard instantiateViewControllerWithIdentifier:#"loginViewController"];
NSLog(#"login push: %#", loginViewController);
[self presentModalViewController:loginViewController animated:YES];
NSLog(#"done push");
}
Log:
2012-01-13 10:18:08.217 App[1101:707] login push: <LoginViewController: 0x472fe0>
2012-01-13 10:18:08.330 App[1101:707] done push
I tried to load it in the Root or detail view, it works but its not the right place and xcode gives the message:
2012-01-13 10:18:08.807 App[1101:707] Unbalanced calls to begin/end appearance transitions for <MainSplitViewController: 0x464bc0>.
My first idea is to begin with the login view and after login push the splitview controller. But I found out that the splitview controller has to be the root view.
To push another ViewController in viewDidLoad is very early. Maybe the current ViewController is presented with animation and you try to present another ViewController with animation ...
You should try moving the display of your LoginController to viewDidAppear ...