Im trying to use presentViewController inside a UIView.
http://img145.imageshack.us/img145/6334/appt.png
When I click he "+" button at the top/right, I want to replacer the tableview at the right (in the grey part of the image) by a UIViewController.
- (void)add:(id)sender
{
UIViewController *controller = [self.storyboard instantiateViewControllerWithIdentifier:#"testview"];
[self presentViewController:controller animated:YES completion:NULL];
}
Of course by doing this, the whole screen is replaced..
I want something like this:
[contentView addSubview:controller];
or
[contentView presentViewController:controller animated:YES completion:NULL];
where contentView is an UIView containing the tableview
I found this addChildViewController and presentViewController but I don't think that can help me out
Thanks
EDIT:
Use ContainerView in storyboard solved my problem
You can add the controller's view as a subview of your contentView. Be sure to keep a strong reference to the controller when you do that though.
Another approach would be to make the new view owned by the presenting controller instead of a second controller and simply hide/show views as needed.
edit your statement:
[self.navigationController presentViewController:controller animated:YES completion:NULL];
try this and then let me know if it worked!
I am not sure if I understand you right. From your picture I believe you are programming for an iPad, and you want to cover the whole view partly by another view. If so, you could use a UIPopoverController, which does exactly this.
A PopoverController seems to be what you need. Here is some boilerplate code:
UIPopoverController* aPopover = [[UIPopoverController alloc]
initWithContentViewController:navigation];
self.aPopoverController = aPopover;
[self.aPopoverController presentPopoverFromRect:nil inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
aPopoverController is a property of the class.
#property UIPopoverController* aPopoverController;
If I understand clearly. This would help you out
SomeViewController *viewController=[[SomeViewController alloc]init];
[viewController setFrame:CGRectMake(x,y,width,height)];
[self.view addsubview:viewController.view];
Sorry if Iam wrong...
Related
I have two classes, machineClass and buttonsClass... From buttons class, I want a button to programmatically push into the machineClass.
Ive gotten that to work with:
machineClass *mc = [self.storyboard instantiateViewControllerWithIdentifier:#"machineClass"];
mc.passedString = purchase;
[self presentViewController:mc animated:YES completion:nil];
However, this uses the default segue animation (where the view comes up vertically), and I think my app would look so much nicer if I used the cross dissolve transition instead.
Can anyone help? The best solution I've come up with is to change it to:
[self presentViewController:mc animated:NO completion:nil];
But I don't like this as much...
Thanks!
You can set the target view controller's modal transition style in the storyboard. Or in code:
machineClass *mc = [self.storyboard instantiateViewControllerWithIdentifier:#"machineClass"];
mc.passedString = purchase;
mc.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentViewController:mc animated:YES completion:nil];
I have 4 ViewControllers, startViewController as the initial View Controller. This contains my intro. After its finish, it will [self presentViewController:vc animated:YES completion:NULL]; into my menuViewController.
startViewController ------> menuViewController ------> C1ViewController
\
\ ------> ImportantViewController
In my menuViewController are buttons for the two ViewController like the above illustration. Also I presented them in the View with this: [self presentViewController:vc animated:YES completion:NULL]; I return tomenuViewController with this [self dismissModalViewControllerAnimated:YES];
What I wanted is to make the ImportantViewController to be the like the parent view or the mainVIew even if I go to other Views. What I need is when ImportantViewController is presented when I go to either C1ViewController or menuViewController it wont be deallocated, or its content there will still be retained.
Is it possible? And How?
I don't know much about what parent and child view controllers for so I dont know what to implement in my problem. Thank you.
BTW, Im using Storyboard.
make the ImportantViewController the root view of a UINavigationController, you will present a UINavigationController instead of the ImportantViewController,
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:YourImportantViewControllerOBject];
//insted of presentModalViewControlle with YourImportantViewControllerOBject you do
[self presentModalViewController:navigationController animated:YES];
Now in ImportantViewController to present new view controller you will do the following
[self.navigationController pushViewController:yourC1ViewController animated:YES];
I am not 100% on what you want to do, but if you use ARC, setting the ImportantViewController to __strong it will be retained for you. Why dont you make the ImportantViewController the parent by creating the needed view controllers programmatically in the ImprotantViewController.m?
// ImportantViewController.m
// non ARC
FirstChildViewController *firstChild = [[FirstChildViewController alloc] initWithNib#"FirstChildViewController" bundle:nil];
//set firstChild.view position here if needed. e.g. .center = CGPointMake(x,y);
//now add firstChild to the parent
[self addSubview:firstChild];
[firstChild release];
You can do the same with the second view or any number of views. I find this nicer than presenting the view controller. You can also add Core Animations to the children views and create a nice UI.
Did this answer your question? Maybe I didnt get exactly what you wanted. :)
I have a UIViewController class and a second which I want to push modally preferably. However I can't seem to call [self pushModalViewController:...], how come?
What requirements do I need to meet to be able to do so?
I am doing this and getting a black view pushed:
vc = [[ViewController alloc] init];
[vc setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
[self presentModalViewController:vc animated:YES];
I have made my view controller in my storyboard and given it a custom class. I am trying to present this view modally via this class as seen in my code.
Any help much appreciated, thanks.
'push' and 'modal' don't belong together in the same thought. You can:
present a modal view controller, preferably using -presentViewController:animated:completion:, which is the modern replacement for -presentModalViewController:animated:
push a view controller onto the navigation stack, assuming that you're using a UINavigationController. To do that from a view controller, use:
[self.navigationController pushViewController:foo animated:YES];
You're actually looking for [self presentModalViewController:myViewController.view animated:YES]
How are you initing this viewcontroller. From the posted code, I assume it is being initialized to a blank view.
Maybe you can init it from a nibname or something?
vc = [[ViewController alloc] initWithNibName:#"NibName" bundle:nil];
[vc setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
[self presentModalViewController:vc animated:YES];
Also another thing to note, if this is a custom class and no nib file, is there any code in initWithCoder? How does the viewDidLoad looks like?
I'm having a little predicament switching between views, here.
Alright, so, I have this view controller class in my iPhone project called "BaseViewController," which is the default, which has a button called "GoToNextView." I added another ViewController to the storyboard called "NextViewController," and then I created another custom view controller class called "NextViewController." Under the inspector window for NextViewController on the storyboard I changed its custom class to "NextViewController;" I'm assuming everything should be hooked up, now. When I click on the "GoToNextView" button, though, the application stops with a SIGABRT message.
Here's the code for my button click action in the BaseViewController class.
- (IBAction)Transition_Next:(id)sender
{
nextViewController = [[NextViewController alloc]
initWithNibName:#"SecondView"
bundle:[NSBundle mainBundle]];
[self.view addSubview:nextViewController.view];
}
What might I be doing wrong, here?
Thanks in advance...
You can use:
- (IBAction)Transition_Next:(id)sender
nextViewController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:nextViewController animated:YES];
}
Instead of your code and it should work! Hope that helps!
You can use [self.navigationController pushViewController:nextViewController animated:NO]; or if you don't have a navigation controller, you may use
[self presentModalViewController:nextViewController animated:NO]; instead of [self.view addSubview:nextViewController.view];
let me explain you my problem:
I have an UIViewController with 2 UIViews.
I have a button in one of my UIView and i call a methode from my UIViewController.
[controller actionMainSettings];
And this is the methode:
-(void)actionMainSettings{
MainSettings *mainController = [[MainSettings alloc] initWithNibName:#"MainSettings" bundle:nil];
[self.navigationController pushViewController:mainController animated:YES];
[[self navigationController] setNavigationBarHidden:YES animated:NO];
[mainController release];
}
MainSettings is an UIVewController...
and nothing happen...
When i put my button in my UIVIewController ([self.view addSubview:buttonSettings];) it's ok but i want to put it in another UIView.
Can someone explain me what happen?
thx
I am not very sure about this but you could try super.navigationController instead of self.
Also, from the look of your code, I would assume it's a settings view. I would recommend that you use [self presentModalView:yourView animated:YES]. You can look at the UIView documentation for a range of animations.