Opening a ECSlidingViewController from a Normal View Controller - ios

I'm using ECSliding and I have this problem!
In my project there are this files:
InitViewController (ECSlidingController)
FirstViewController (UIViewController)
SecondViewController (UIViewController)
LeftMenuViewController (UIViewController)
ThirdViewController (UIViewController)
I use InitView to instatiate my FirstView as the topview, sliding to right opens the LeftMenu.
In the LeftMenu there are 2 buttons, one button loads as topview the FirstView, the second one loads the SecondView.
In my First and SecondView there is an identical button that loads the ThirdView not as topview controller but as a new view:
ThirdViewController *third = [self.storyboard
instantiateViewControllerWithIdentifier:#"Third"];
[self presentViewController:third animated:YES completion:nil];
In my ThirdView are 2 buttons, one button loads the FirstView, the second one loads the SecondView.
As the ThirdView is not a topview but another view I have to recall ECSliding to open my FirstView or SecondView.
I succeeded loading the FirstView from my ThirdView by using my InitView
InitialSlidingViewController *home = [self.storyboard
instantiateViewControllerWithIdentifier:#"Init"];
[self presentViewController:home animated:YES completion:nil];
But how can I load the SecondView from my ThirdView?
My question basically is how can I load something that use ECSliding after a normal View.

From Third we want to go back to the sliding view controller and change the top view controller. What you're currently doing with this code:
InitialSlidingViewController *home = [self.storyboard instantiateViewControllerWithIdentifier:#"Init"];
[self presentViewController:home animated:YES completion:nil];
Is creating an entirely new sliding view controller to show. Eventually, by doing this, you'll run out of memory because you'll have hundreds of presented views allocated and never visible.
So, what we want to do is give Third a property:
#property (weak, nonatomic) ECSlidingViewController *slideController;
And we want to set that property before presenting Third:
ThirdViewController *third = [self.storyboard instantiateViewControllerWithIdentifier:#"Third"];
third.slideController = self.slidingViewController;
[self presentViewController:third animated:YES completion:nil];
Now, when one of the buttons is pressed on third we can say: "what's on display? Can we just dismiss or do we need to change and dismiss?":
- (void)oneButtonPressed {
if ([self.slideController.topViewController isKindOfClass:[SecondViewController class]]) {
FirstViewController *first = [self.storyboard instantiateViewControllerWithIdentifier:#"First"];
self.slideController.topViewController = first;
}
[self dismissViewControllerAnimated:YES];
}
You need to write the corresponding method for twoButtonPressed and you're done.
For your new comment, rather than presenting the third, instead you should put it into a navigation controller and present that. Then, when you need to present fourth and fifth you just push them into the nav controller and pop them off again. If required you can also give them a reference to the slideController.
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController :third];
[self presentViewController:nav animated:YES completion:nil];

Related

how to add New UIViewCOntroller Over UiView

I have added subview in a UIViewController and I want a new UIViewController Should be loaded on click of button.
Challenge is I am not able to use button in new UIViewController.
Code which I have write:
DetailsOfDayViewController *aViewController =[[DetailsOfDayViewController alloc] initWithNibName:#"DetailsOfDayViewController" bundle:nil];
aViewController.dateParsing = dateparsing;
[self addSubview:aViewController.view];
This will fix your issue. This is happening because your view controller is being deallocated when you don't have any strong pointers on it.
DetailsOfDayViewController *aViewController =[[DetailsOfDayViewController alloc] initWithNibName:#"DetailsOfDayViewController" bundle:nil];
aViewController.dateParsing = dateparsing;
[self addChildViewController:aViewController];
[self addSubview:aViewController.view];
Another fix will be connecting this view controller to a property:
#property(nonatomic,strong) DetailsOfDayViewController *aViewController;
And change your code like this:
self.aViewController = [[DetailsOfDayViewController alloc] initWithNibName:#"DetailsOfDayViewController" bundle:nil];
self.aViewController.dateParsing = dateparsing;
[self addSubview:self.aViewController.view];
For showing another controller you can following options
1. Add SubView
newViewControllerObj.view.frame = oldViewControllerObj(self).view.frame
[oldViewControllerObj(self).view.newViewControllerObj.view];
2. Present
[oldViewControllerObj(self) presentViewController: newViewControllerObj animated:YES completion:nil];
3. Push using Navigation (For this you already have to set navigation controller as root controller)
[oldViewControllerObj(self).navigationController pushViewController:newViewControllerObj animated:YES];

How to move from one view controller to another with an Action?

IM not Using Storyboard.
Ive place a button, on my PlayViewController and when tapped I want the user to go back to the Main menu which is the ViewController.
When I add this line of code:
- (IBAction)backToMenu:(id)sender {
[self dismissViewControllerAnimated:YES completion:nil];
}
It dismisses the ViewController - I want it to present it, So I used:
ViewController *viewcontroller = [[ViewController alloc]initWithNibName:#"ViewController" bundle:nil];
viewcontroller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentViewController:viewcontroller animated:YES completion:nil];
I get this ERROR: "Receiver 'ViewController' for class is a forward declaration"
I need to present my main menu, how am i supposed to do it?
You need to import the target view controller in your PlayViewController:
#import "ViewController.h"

Presentview(full screen) controller while dismissing View1 which is model view itself

I have an ipad app.
I am trying to open view 2 (kind of push view) full with entire screen. how normally do with push view or UIModalPresentationFullScreen. but my base view which is view 1 is also modal view.
so i was trying to open view 2 when view 1 get dismiss…
- (void) handleNewButton :(int)id
{
[self dismissViewControllerAnimated:YES
completion:^{
NewViewController *View2 = [NewViewController alloc] init];
View2.modalPresentationStyle = UIModalPresentationFullScreen;
View2.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentViewController: View2 animated:YES completion:nil];
}];
}
but my view 2 is not opening. i know i can not do push view. But is there any way to achieve it?.
When you do this dismissViewControllerAnimated the UIViewController (self in this case) is gone, in the sense that he is not on the screen anymore, if it has been released or not, that's another story. The reason for you to not be able to show the View2 (very poor name, it should at least ViewController2) is because you are trying to show it from a UIViewController that is not on the screen anymore.
So, what can you do?
The current self in the context of the handleNewButton method, in theory was presented by another UIViewController, that's from where you want to present your View2.
Probably the quickest way of implementing of what I said, would probably be with a notification described here. Although I would do it with a block, so when the self would be created, I would pass a dismissiCompletionBlock that would be called when that UIViewController was dismissed.
try to allocate NewViewController with nib name if you are not using storyboard,
[self dismissViewControllerAnimated:YES
completion:^{
NewViewController *n=[[NewViewController alloc]initWithNibName:#"NewViewController" bundle:nil];
View2.modalPresentationStyle = UIModalPresentationFullScreen;
View2.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentViewController: View2 animated:YES completion:nil];
}];
or if you are using storyboard get NewViewController using identifier.

Dismiss UIViewController after presenting another one

I'm developing a single view iOS 5.0+ app and I'm going to navigate throw my ViewControllers this way:
SearchViewController* search =
[[SearchViewController alloc] initWithNibName:#"SearchViewController"
bundle:nil];
[self presentViewController:search
animated:NO
completion:nil];
My question is, if I'm opening SearchViewController from HomeViewController, is HomeViewController dismissed after SearchViewController is shown?
I have a lot of UIViewControllers and I don't know if all of them will be on memory while user is navigating between them.
If You want to Present Only one Viewcontroller you can try like,
SearchViewController* search =
[[SearchViewController alloc] initWithNibName:#"SearchViewController"
bundle:nil];
[self dismissViewControllerAnimated:NO completion:^{
[self presentViewController:search
animated:NO
completion:nil];
}];
When you present a ViewController from another ViewController, they never get released from memory. To release them from memory you need to explicitly dismiss them.
The method presentViewController:animated:completion: sets the
presentedViewController property to the specified view controller,
resizes that view controller’s view and then adds the view to the view
hierarchy.
So you see you are getting a stack of ViewControllers and adding a View on top of another.

Change view in one XIB

I'm trying to make an app using Interface Builder (instead of Storyboard) for the first time, but I'm stuck. Is it possible to change view using a ViewController in the same XIB?
I'd like that when I tap a button, the view changes to the other ViewController present in the same XIB file. Must I call back an action? If yes, which?
If you have 2 view controllers with 2 .xib files, like this
You can present the NextViewControler from your ViewController's button press method,
-(IBAction) yourButtonPressed:(id)sender;{
NextViewController *nextViewController = [[NextViewController alloc] initWithNibName:#"NextViewController" bundle:nil];
[self presentViewController:nextViewController animated:YES completion:nil];
}
EDIT :
You can present the same viewcontroller like this.
-(IBAction) yourButtonPressed:(id)sender;{
ViewController *viewController = [[ViewController alloc] initWithNibName:#"ViewController" bundle:nil];
[self presentViewController:viewController animated:YES completion:nil];
}

Resources