From my current view I called another view using addsubview and when I click ok I want to push another view that will serve as my main view for the whole operation
call the first view:
dc=[[DriverConfirmation alloc]init ];
[[dc view]setFrame:CGRectMake(186, 141, 616, 443)];
[self view]addSubview:dc.view];
when I press ok button I removed it using
[[self view]removeFromSuperview];
but I cannot push the next view using this:
RouteManagement *rm=[[RouteManagement alloc]init];
[self.parentViewController pushViewController:rm animated:NO];
[rm release];
Thank you for any assistance you will give.
Related
Ok, I'm still pretty new; so, please bear with me.
I'm creating a custom app for a friend that displays a list of work orders in a table view. Clicking on a work order brings them to a detail view. In the detail view, there is a button that uses a push to present another screen called completion view. From the completion view, they click a button that uses the following code to present a nib for signature capture.
SigScreenViewController *sigScreenViewController=[[SigScreenViewController alloc] initWithNibName:#"ViewController_iPhone" bundle:nil];
[self presentViewController:sigScreenViewController animated:YES completion:nil];
The signature screen uses: https://github.com/jcmontiel/SignatureViewExample for capturing the signature and does it well. I have a button that completes the transaction and sends it back to the table view list.
My problem is that I cannot create a button that will return me to the completion view in the storyboard.
I've tried the following in a button:
[self dismissViewControllerAnimated:YES completion:nil];
or
[self.navigationController popViewControllerAnimated:YES];
I'm open for any suggestions on how I can do it.
Thanks in advance!
Have you tried having the UIViewControllers embedded in a navigation controller ?
Are you pushing from a UIViewController in UIStoryboard to a NIB file?
If so check out this sample project that pushes from storyboard to a NIB:
// in a navigation controller
// to load/push to new controller use this code
// this will be next screen
DetailsViewController *detailsViewController = [[DetailsViewController alloc ]init];
[self.navigationController pushViewController:detailsViewController animated:YES];
// to go back or pop controller use this
// now it will send back to parent screen
[self.navigationController popViewControllerAnimated:YES];
Hi i have been working on an iOS app.What i am doing is navigating among diffrent view controllers. But the problem is i want finish the current view controller from emoery and then move to the next view controller.
I am using `[self.view removeFromSuperview]; for finishing the cureent view & using
self.loginView = [self.storyboard instantiateViewControllerWithIdentifier:#"LOGIN"];
[self presentViewController:self.loginView animated:NO completion:nil];
for moving to next view controller but the thing is i am not able to remove it from memory.
Please tell me how can i do it?
Thanks in advance.
`
It's better to create a container view controller which manages your view controllers. For example, in viewDidLoad: of container controller you add current controller:
[self addChildViewController:self.currentViewController];
[self.currentViewController didMoveToParentViewController:self];
[self.view addSubView:self.currentViewController.view];
//here set up currentViewController view's frame or constraints if needed
When you need to open login controller, do this:
[self addChildViewController:loginViewController];
[self.loginViewController didMoveToParentViewController:self];
[self.view addSubView:loginViewController.view];
//here set up loginViewController view's frame or constraints if needed
//then remove current view controller
[self.currentViewController willMoveToParentViewController:nil];
[self.currentViewController removeFromParentViewController];
[self.currentViewController.view removeFromSuperview];
Remove from superview will remove it from the current view, but OS won't remove it until he needs to (this is topic for more explanation, let's say it won't remove it asap).
If you want something deleted just call it nil:
self.view = nil;
This will make the pointer to nil, so view won't be there any more. (the view really will be somewhere but you won't have access to it)
I am revising your code
self.loginView = [self.storyboard instantiateViewControllerWithIdentifier:#"LOGIN"];
[self presentViewController:self.loginView animated:NO completion:nil];
What you are doing here is presenting your login viewcontroller.
self: This is the instance of the viewcontroller you are currently working on. So how could you remove self from memory. (Not Possible)
You can approach alternate ways.
For example: 1. Changing root view controller
Pop to root view controller and then Push Login View controller.
If you try to remove not only UIView but the whole UIViewController from a navigation controller stack use this snippet
NSMutableArray *stack = [[NSMutableArray alloc] initWithArray: self.navigationController.viewControllers];
[stack removeObject:yourController];
self.navigationController.viewControllers = stack;
Be aware of using this only when you've already pass to the next controller view.
UPD:
Oh, now I see what you are trying to do. And I can't figure out, why you're trying to step your controllers this way (modally). I think you should use UINavigationController with navigation segues defined directly from your storyboard. Look at this article where apple purely explains what navigation is. That article is about modal views
I have a root view controller with subview to be wrappers for views of child view controllers. The basic idea is my root controller has a left and right view controller, both present on screen (similar to a splitviewcontroller). On load a modal view pops up over the root view controller and asks for details. The modal view then contacts a server, and is dismissed after getting a response. The root controller then adds the child view controllers with the following code:
[self addViewController:self.leftViewController];
[self addViewController:self.rightViewController];
[self addView:self.rightViewController.view ToWrapper:self.rightViewWrapper];
[self addView:self.leftViewController.view ToWrapper:self.leftViewWrapper];
Where add view controller is:
[self addChildViewController:controller];
[controller didMoveToParentViewController:self];
and addViewToWrapper just adds the view controller's view to the relevant subview of the rootViewController as follows:
[[viewWrapper.contentView subviews] makeObjectsPerformSelector:#selector(removeFromSuperview)];
newSubview.frame = viewWrapper.contentView.bounds;
newSubview.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
[viewWrapper.contentView addSubview:newSubview];
99% of the time this works fine. Both views appear instantly and viewWillAppear fires in both child controllers. However, occasionally the screen stays white for a brief period and viewWillAppear doesn't fire in the right view controller (EDIT: and the left). All of the other view lifecycle methods fire, just not viewWillAppear.
Unfortunately, I can't give code for the whole class as it is complex and proprietary. But are there any clues in this description for this intermittent behaviour?
Some thoughts on this:
ONE
It looks like your containment methods are not being called properly. They should look like this for each viewController:
[self addChildViewController:controller];
[self.view addSubview:controller.view];
[controller didMoveToParentViewController:self];
The view should be added to the superview in between the addChild and didMove calls.
TWO
To my knowledge, there cannot be more than one presentation or dismissal occurring at a time. I.e. If you are trying to present (add) your child viewControllers at the same time as the modal is being dismissed, you will see an error in the console log and your "add" operation will not occur.
My recommendation would be to create a delegate protocol on the modal viewcontroller. And in the completion block of dismissViewControllerAnimated:completion:, call your delegate method:
[self dismissViewControllerAnimated:YES completion:^{
if ([weakSelf.delegate respondsToSelector:#selector(settingsViewControllerDidDismiss:)])
{
[weakSelf.delegate settingsViewControllerDidDismiss:self];
}
}];
And in your rootViewController, you would begin adding its children inside of settingsViewControllerDidDismiss or whatever you decide to call that method. The point is that the "add" operation begins AFTER the dismissal operation.
Hope this helps.
I am experiencing an issue and I believe it's due to me incorrectly removing my view. I will try to explain and hope all can follow.
I have a UISplitview app which essentially has two views. The main detail view, and a view which is essentially a map. Upon selecting a certain string in the table this code is called (this code is in the detailview but the rainObject is passed in from a UIViewController.
-(void)setReceivedRainObject:(id)receivedRainObject{
if ([receivedRainObject isEqualToString:#"Test"]){
mapViewController *mapView=[[mapViewController alloc]initWithNibName:#"mapViewController" bundle:nil location:0];
[self.navigationItem setHidesBackButton:NO animated:NO];
[self.navigationController setNavigationBarHidden:NO animated:YES];
[self.navigationController pushViewController:mapView animated:NO];
}
}
So the above code loads my map fine in the detailscreen as expected.
However, when I click the first option (test) from the left view controller, it calls a new view controller (viewcontroller2 with a row named test2) and that second controller calls a third( viewcontroller3 with a row named test3)
On the viewDidDisappear of viewcontoller3 and in the viewWillAppear of test I have this code
[self.detailViewController.navigationController popViewControllerAnimated:NO];
So when I drill down to viewcontroller, when I click the backbutton, it pops off one map, and when testview loads it pops the second. leaving my detail view showing exactly how I started.
However, I've noticed that if I clicked the "test" button twice, and try to go back, there is an "extra screen" that was supposed to be remove with pop. Would like to know how to remove this mass of views or to stop the program from adding so many.
Thanks
Just use
mapViewController *mapView=[[mapViewController alloc]initWithNibName:#"mapViewController" bundle:nil location:0];
[self.navigationController pushViewController:mapView animated:YES];
to navigate through the view controllers.
I have the first ViewController that has 2 buttons on it. One to go to ViewController1 when clicked and the other to go to ViewController2 when clicked. When i click the first button it takes me to ViewController1 but when i click the second button it goes to a black screen and gives the warning:
Warning: Attempt to present on while a presentation is in progress!
What am I doing wrong?
Here is my code:
-(IBAction)goToYourClosetViewController: (id)sender{
YourClosetViewController *closet = [[YourClosetViewController alloc] initWithNibName:nil bundle:nil];
[self presentViewController:closet animated:YES completion:NULL];
}
-(IBAction)goToPlanOutfitViewController: (id)sender{
PlanOutfitViewController *planOutfit = [[PlanOutfitViewController alloc] initWithNibName:nil bundle:nil];
[self presentViewController:planOutfit animated:YES completion:NULL];
}
Are you pressing the first button and then the second button in rapid succession by any chance?
If that's it then you need to disable your buttons while the modal presentation is in progress, and re-enable them in your completion blocks.
If not, then how are you displaying the first view controller? (The one that contains these 2 buttons)
You are probably trying open the second view controller before you close the first view controller. That's the kind of error message in such cases.
When you go back to your initial view controller from either first or second view controller, do this:
[FirstViewControllerInstance dismissModalViewControllerAnimated:YES];