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.
Related
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...
I founded that the problem is the place where I'm calling the showNextView. I have another interface webService where i communicate with server and parse xml. When the parsing is finished with method parserDidEndDocument I'm calling the delegate method where is changed the view and show modal view. But when i call all that methods it will return to endDocument and xmlParseChunk and so on. It looks like the parserDidEndDocument is not realy the last method and somehow it mess with navigationcontroler. When i call the method for showig nextView with button it works.
The code which is working on button. In delegate method called from parserDidEndDocument is not working correct.
-(void)showNextView
{
UIViewController *nextView = [self.storyboard instantiateViewControllerWithIdentifier:#"vcTrabantInfo"];
[[nextView navigationController] setNavigationBarHidden:NO animated:NO];
[[self navigationController] pushViewController:nextView animated:YES];
UIViewController *picker = [[UIViewController alloc] init];
[picker setModalPresentationStyle:UIModalPresentationFormSheet];
[[self navigationController] presentModalViewController:picker animated:YES];
}
As usualy the problem was between keyboard and seat. The problem was that my modal views haven't been dismissed before i call another modal view :). So keep in mind that all is done in viewDidDisappear.
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];
I am a newbie iPhone Programmer and have a question regarding how to access methods of a Parent View Controller.
In my program when the program first loads (applicationDidFinishLaunching) I do the following code:
[window addSubview:rootViewController.view];
[window makeKeyAndVisible];
which basically calls this
- (void)viewDidLoad {
HomeViewController *homeController=[[HomeViewController alloc] initWithNibName:#"HomeView" bundle:nil];
self.homeViewController=homeController;
[self.view insertSubview:homeController.view atIndex:0];
[homeController release];
[super viewDidLoad];
}
Now, I have an IBAction call on HomeViewController that I want to have it call a method in root View Controller
I want to call this method
- (void)loadNewGame
{
self.questionViewController = [[QuestionViewController alloc] initWithNibName:#"QuestionView" bundle:nil];
//[homeViewController.view removeFromSuperview];
[self.view insertSubview:questionViewController.view atIndex:0];
}
So my question is how do I call a method from the Parent View controller?
I've tried
[self.view removeFromSuperview];
[self.parentViewController loadNewGame];
but that doesn't seem to work. Could someone please ploint me in the right direction.
Thanks in advance
Scott
First off, typically you call [super viewDidLoad] first in your viewDidLoad.
You will have to have an instance variable in your homeController class for your rootViewController. Then you could have a method in homeController:
- (void) loadNewGame
{
[self.rootViewController loadNewGame];
}
This is one of many different ways to accomplish this. You may want to move the method to homeController completely. Or you may wish to have IB use the rootViewControllers' methods directly...
Here is another discussion of this.
First off your code doesn't really make sense. Why are you adding your HomeViewController in a -viewDidLoad call. If you want to load the HomeViewController as the initial view, you should set that in Interface Builder instead of RootViewController. When you want to display a new view controller, you should be using a navigation controller stack and pushing the new view controller onto it with [[self navigationController] pushViewController:newViewController animated:YES].
Assuming you get that sorted, you should create a delegate (id) field for your child view controller that you can set when you instantiate the new view controller. So your code might look something like this:
HomeViewController *homeController=[[HomeViewController alloc]
initWithNibName:#"HomeView" bundle:nil];
[homeController setDelegate:self];
[[self navigationController] pushViewController:homeController animated:YES];
[homeController release];
Then, when your action gets fired in the HomeViewController, you can check to see if the delegate is set and if so, call the selector in question, like this:
- (IBAction)action:(id)sender;
{
if (delegate && [delegate respondsToSelector:#selector(loadNewGame)])
[delegate performSelector:#selector(loadNewGame)];
}
You might want to read Apple's docs on how to use the navigation controller stack. This might help clarify some things.
In navigationcontroller application , i used
ViewController *modalViewController=[[ViewController alloc]initWithNibName:#"ViewController" bundle:nil];
[[self navigationController]presentModalViewController:modalViewController animated:NO];
[modalViewController release];
above code will load an anotherviewcontroller....
I want to push one moreviewcontroller from this viewcontroller(ViewController)...
Can any one help me?
Thanks in advance...
If you actually want to push view controllers in the modal view then the modal view needs to be a UINavigationController. So you would do something like this:
ViewController *modalViewController=[[ViewController alloc]initWithNibName:#"ViewController" bundle:nil];
UINavigationController *modalNavController = [[UINavigationController alloc] initWithRootViewController:modalViewController];
[modalViewController release];
[self.navigationController presentModalViewController:modalNavController animated:NO];
[modalNavController release];
I generally wouldn't recommend doing it because it is confusing to the user, but in some cases it makes sense.
Do you mean "push" as in pushViewController, or as in presentModalViewController?
In presentModalViewController