Push UIView after Modal - ios

I'm using a modal transition to move between view1 to view2 and i want to use pop transition (programmatically) from view2 to view3, but it doesn't work (I am using navigation controller as root):
the code is (in view2):
view3 *controller = [self.storyboard instantiateViewControllerWithIdentifier:#"view3"];
[self.navigationController pushViewController:controller animated:YES];
how should the code be?

All looks good to me in terms of code.
You should provide information about why this is not working... Are you getting an error? IF so where?
How do you initate the push to the new controller? Try using NSLog(#"Hello"); to make sure that this is being called correctly.
Further to this, the issue could be that the storyboard is not being returned with self.storyboard. You can always try
UIStoryboard *appStoryboard = [UIStoryboard storyboardWithName:#"YOUR_STORYBOARD_NAME_HERE" bundle:nil];
Then use
view3 *controller = [appStoryboard instantiateViewControllerWithIdentifier:#"view3"];

Related

IOS/Objective-C/Storyboard: Prevent ViewController From Launching Modally

I want a viewcontroller to launch using a show transition, not modally from the bottom. Normally when I use the following code that's what happens. However, in this case, it is launching as a modal controller from the bottom up. Is there a switch I don't know about or could something be set in Storyboard that is causing this VC to launch modally from the bottom instead of showing?
UIStoryboard *storyBoard = self.storyboard;
IDImportEventsOnboard *importEvents =
[storyBoard instantiateViewControllerWithIdentifier:#"importEventsOnboard"];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController: importEvents];
[self presentViewController:nav animated:YES completion: nil];
The VC is embedded in a navigation controller.
Should I be using showViewController directly to the targetVC without going through the Nav? Or a pushViewController What is a proper, robust way to show a VC with a show transition?
Thanks in advance for any suggestions.
In the above code you are 'presenting' a new NavigationController from a ViewController. In order to do a push/show transition, that needs to be done on an instance of a NavigationController. If your current ViewController is already in a NavigationController, you can push the new ViewController onto the current NavigationController stack. For Example:
UIStoryboard *storyBoard = self.storyboard;
IDImportEventsOnboard *importEventsVC =
[storyBoard instantiateViewControllerWithIdentifier:#"importEventsOnboard"];
[self.navigationController pushViewController:importEventsVC animated:YES];

Navigation from one view to another view in IOS (objective c)

I am new in IOS. I am confused in navigation.I have looked 3,4 methods to navigate from one view to another view controller.
First
DashboardViewController *dashboard = [self.storyboard instantiateViewControllerWithIdentifier:#"DashboardViewController"];
[self.navigationController pushViewController:dashboard animated:YES];
Second :- Using push segue on clicking button.
Third :- I'm not clear for it, That is array of view controller. In which we get the view controller and then navigate.
Fourth:-
UIStoryboard* storyboard = [UIStoryboard storyboardWithName:#"Main"
bundle:nil];
UserDashboardViewController *users =
[storyboard instantiateViewControllerWithIdentifier:#"UserDashboardViewController"];
[self presentViewController:users
animated:YES
completion:nil];
I am confused which is best way for navigation, and most important how to navigate using array of view controllers. Please help me, Thanks.
This is the best way in my point of view.

Dismissing (or popping) a NavigationController I added manually does not work

In my AppDelegate I have the following code which is executed after receiving a notification:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
UINavigationController *navigationController = (UINavigationController *)[storyboard instantiateViewControllerWithIdentifier:#"VideoPlayback"];
VideoPlaybackViewController *videoPlaybackViewController = (VideoPlaybackViewController *)[navigationController topViewController];
videoPlaybackViewController.publishing = YES;
[(UINavigationController*)self.window.rootViewController pushViewController:navigationController animated:NO];
That successfully brings up the new ViewController and apparently adds it to the navigation stack, since I can use the back button on the navigation bar to go back and subsequently dismiss the view controller.
The problem is, I don't want to use the navigation bar. In fact, I would like to hide the back button. Unfortunately, when I try to dismiss the viewcontroller using the method(s) it should use, it does nothing. I've tried using both of these to dismiss the view controller:
[self dismissViewControllerAnimated:YES completion:nil];
[self.navigationController popViewControllerAnimated:YES];
What am I doing wrong? Thanks.
You're trying to push a navigation controller into a navigation controller, which won't end well.
[(UINavigationController*)self.window.rootViewController pushViewController:navigationController animated:NO];
probably needs to be changed to:
[(UINavigationController*)self.window.rootViewController pushViewController:videoPlaybackViewController animated:NO];

iOS: How to programmatically navigate/jump to different scenes managed by Navigation Controller?

I have a series of views that are managed under a Navigation Controller. Is there a way to programmatically (in iOS5+) jump (push/pop) to different views? For instance, I have
NavigationController->RootViewController->DetailViewController1->DetailViewController2->DetailViewController3
How can I, say, jump from RootViewController to DetailViewController3, and then jump back to DetailViewController1?
Thanks.
You can try something like this.
Get your VCs from storyboard. (You have to set identifiers in storyboard)
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
UIViewController *DetailViewController1 = [storyboard instantiateViewControllerWithIdentifier:#"DetailViewController1Identifier"];
UIViewController *DetailViewController3 = [storyboard instantiateViewControllerWithIdentifier:#"DetailViewController3Identifier"];
Push VCs way you need.
[self.navigationController pushViewController:(DetailViewController1) animated:YES];
[self.navigationController pushViewController:(DetailViewController3) animated:YES];
Now, when you press "back" you'll see DetailViewController1.

Linking a new viewcontroller to Storyboard?

There is probably a simple solution but I can't figure it out.
I am using storyboards for the interface.
I start with a tab bar controller, but before the user is allowed to use the app the user has to authenticate himself trough a loginview which is modally pushed at the start.
I want to configure the loginview at the same storyboard, but I can't seam to figure out how to link the view controller at the storyboard and my code.
What I have done:
Create a new UIViewController subclass trough file > new > new file.
Drag a new UIViewController in the story board
Set the class in the custom class tab
drags a UILabel for test purpose.
run
No label...
Pull on a new UIViewController that will act as the login view controller onto the MainStoryboard. In the attribute inspector change the identifier to LoginViewController (or something appropriate). Then add
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:#"LoginViewController"];
[vc setModalPresentationStyle:UIModalPresentationFullScreen];
[self presentModalViewController:vc animated:YES];
}
to the First view controller and the login screen will be loaded from your storyboard and presented.
Hope this helps.
The answer by Scott Sherwood above is most correct answer I found after lot of searching. Though very slight change as per new SDK (6.1), presentModalViewController shows deprecated.
Here is very small change to above answer.
UIStoryboard *sb = [UIStoryboard storyboardWithName:#"Storyboard" bundle:nil];
HomeViewController * hvc = [sb instantiateViewControllerWithIdentifier:#"LoginView"];
[hvc setModalPresentationStyle:UIModalPresentationFullScreen];
[self presentViewController:hvc animated:YES completion:nil];
I'm new in this field. But if the first view controller is a navigation view controller and its rootviewcontroller is a table view controller. If you want to push a view controller like the LoginViewController when you click the cell, and you also want to go back to the table view by using the navigation bar. I recommend this way:
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UIStoryboard *sb = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
UIViewController *controller = [sb instantiateViewControllerWithIdentifier:#"LoginViewController"];
[self.navigationController pushViewController:controller animated:YES];
}
In this way, you can have the navigation.
By the way, I don't know why this kind of problem you asked will appear. I guess when the loginviewcontroller is created in the code, its view is not the view in the storyboard. If someone know the cause, please tell me! thanks!

Resources