iPhone - Remove view and NavigationController - iphone

I have a ViewController which creates a NavigationController and puts a UIView in it.
nvcontrol =[[UINavigationController alloc] initWithRootViewController:menuView];
...
UIView *parent = self.view.superview;
[parent addSubview:nvcontrol.view];
I need to close the view (incl. the NavController) from within the child-viewcontroller.
The following snippet I tried, only closes the view inside the NavController, not the NavController itself. This ends up showing the blue head with a white space below.
[self.view removeFromSuperview];
What could solve this?

I have not tried this but I think something like this should work:
[self.navigationController.view removeFromSuperview];

#traingle_man Are you sure view is a property of uinavigation controller?
If I understand your question correct, this may help
[nvcontrol.view removeFromSuperview];

Related

addSubView to viewController.navigatorController

I have a viewController and I am trying to add a subview to it such that it will cover the whole screen, however this has a navigationController in it so that adding a subView always adds it below the navigation bar, is there a way to simulate a presentModalViewController in cases like this?
You can add the subview to the view controller and then hide the navigation controller from the top or you could still push it to the navigation controller and then just remove the navigation controller from the top again and then you could use pop to go back and forth.
the code to push a view controller is
if(!self.YOURVIEWCONTROLLER){
self.YOURVIEWCONTROLLER = [[YOURVIEWCONTROLLER alloc] initWithNibName:#"YOURVIEWCONTROLLER" bundle:nil] autorelease];
}
[self.navigationController pushViewController:self.YOURVIEWCONTROLLER animatedLYES];
and on the next NEXTView.m add
[self.navigationController setNavigationBarHidden:YES];
remember to create an instance of YOURVIEWCONTROLLER in the .h file. Or you could do a simple
[self.view addSubview:NEWVIEW];
[self.navigationController setNavigationBarHidden:YES];
at least at bear minimum the line for making the navigationController hide is there.
I seem to recall once having a similar problem, and I seem to recall the solution was to add the subview to the navigation controller (as the view controller is already a sub view of the navigation controller) rather than adding it to the view controller.
I recently have similar problems and after spending 5 to 10 min I get the exact solution...
According to my solution I simply add my custom UIView to subview of navigationController.view
Like This :-
[self.navigationController.view addSubview:popOver];
popOver - Your custom UIView
Happy Codding :)
Add the view to the superview of the navigationController's view.
[navigationController.view.superview addSubview:viewController.view];
Perhaps you could hide the navigation bar when you add the subview. I have a method on my ViewController that looks like this:
self.navigationController.navigationBarHidden = YES;
UIView *v = [[UIView alloc] initWithFrame:self.view.frame];
v.backgroundColor = [UIColor redColor];
[self.view addSubview:v];
When that code executes, my navigation bar disappears and a full screen red view replaces it.

iOS - How to remove previous view after loading a new view?

I am practicing multiview but having a small problem.
When my new view gets loaded, I can still see previous view.
How to make previos view invisible??
Here is my code :-
- (IBAction)changeView:(id)sender
{
RedClass *red = [[RedClass alloc] initWithNibName:#"RedClass" bundle:nil];
self.redClass = red;
[red release];
//[self.view removeFromSuperview];
[self.view addSubview:redClass.view];
}
and here is a screenshot :-
And when I uncomment [self.view removeFromSuperview] then my red view is not even getting loaded.
Any help would be appreciated.
Thanks
I think color of your red view may be transparant .
so please check it in your nib file of redclass. also check alpha for your red view it must be 1.
You can not remove your first view here. because it may be loaded at window or other controller. so if you are adding view2 in view 1 and removing view1 then view2 automatically get removed ,because it is already in view1 . so you can not write [self.view removeFromSuperview];
You can declare view variable in .h file. and alloc it in viewDidLoad and don't release it there. Whenever you want to add view use, [self.view addSubview:red]; and when you want to remove you can use [red removeFromSuperview];
[self.view removeFromSuperview] removes the uiview which you is displayed.
So you need to call removefromsuperview for previously loaded view and call addsubview for new one.

Add UINavigationController to subview on iPhone

I have been trying to add this UINavigationController to a subview of my form... All I am getting is a large grey screen.
LiteViewController *lite = [[LiteViewController alloc] initWithNibName:#"LiteViewController" bundle:nil];
[self.view addSubview:lite.navigationController.view];
It should add a full screen navigation controller to the current view.
I found a post, UINavigationController not showing the Root View controller, that worked for me.
Basically you also need to set the view of the navigationController...
[self.view addSubview:navigationController.view];
[navigationController setView:[[navigationController.viewControllers objectAtIndex:0] view]];
You might need a makeKeyAndVisible call.

UIView remove itself from UIScrollView

Following Scenario:
I have a = UIViewController A that contains a UIScrollView
I have a second UIViewController "B" (amongst other things it contains a button)
and add it to the ScrollView of A
myView *mView = [[myView alloc] init];
[myScrollView addSubview:mView.view];
Is there a way that once the button is pressed that it(view) removes itself from the scrollview?
I thought in the direction of setting the delegate of mView to "A" ?! But not sure how that should work in detail....
Any suggestions?
Thanks!
In the controller, you can call:
[self.view removeFromSuperview];
If you have a reference to view you can do the following:
[view removeFromSuperview];
If you don't have a reference, please post more code and I can modify my answer for you.

UIView disappears after modalViewController is removed from superview

In my app I have a tabBarController and in it a navigationController. One of my view controllers is a TableViewController and under the navigationBar i added a uiView as a subview to the view like this:
rectangleInfo = [[UIView alloc] initWithFrame:CGRectMake(0,0,[[UIScreen mainScreen] applicationFrame].size.width,26)]; rectangleInfo.autoresizingMask = (UIViewAutoresizingFlexibleWidth); rectangleInfo.backgroundColor = [UIColor darkGrayColor]; [self.view addSubview: rectangleInfo];
when I click on a cell in the tableView I push an UIViewController like this:
[feedViewController setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
[[self navigationController] presentModalViewController:feedViewController animated:YES];
After i pop the modal view for a couple of times with it from the tableViewNavigationController disappears the rectangleInfo UIView.
I pop my modalview like this:
[[UIApplication sharedApplication] setStatusBarHidden:NO animated:YES];
[self setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
[self dismissModalViewControllerAnimated:YES];
any idea why that subview (rectangleInfo) of the tableViewController dissapears after i remove the modal view from the superview?
thank you in advance.
I'm curious as to what you are trying to do with your rectangleInfo view? By the size of it, it looks like you are trying to mimic the status bar. Why? You can just hide the status bar if you want.
Another thing you can try is to create the UIView visually in Interface Builder. Don't actually add it to your main view, but create it as a separate UIView in the XIB with the appropriate size, etc. Then create an outlet for it in Xcode and connect it. Next, add it as a subview in code when your view controller loads. See if that makes a difference. This is especially strange since you say it only disappears after popping it several times. Do you get the same problem if you push and pop the non-modal way, e.g.:
[[self navigationController] pushViewController:feedViewController animated:YES];
[[self navigationController] popViewControllerAnimated:YES];
i solved the problem by implementing correctly the viewDidLoad and viewDidUnload methods for creating and releasing my subviews.