I have a UIViewController with some buttons that works fine when I add as subview, but when I present this viewcontroller in UIPopoverController none of the buttons trigger actions. Someone knows that problem ?
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"iPhoneStoryboard" bundle:nil];
menuViewController = (MenuListViewController *)[storyboard instantiateViewControllerWithIdentifier:#"menuviewcontroller"];
Buttons inside viewcontroller works if I use:
[self.view menuViewController.view];
But I want to use
popover = [[UIPopoverController alloc]initWithContentViewController:menuViewController];
One thing to look at when you can't interact with UI elements, especially after frame resizes, is to check that your elements are not outside of their parents bounds, check my answer to this question
Related
This was all working while I was using Xcode 6.4. I installed macOS Sierra and Xcode 8 on my machine and this has become broken.
I have a Viewcontroller (vc1) with a UIView on it. Inside this UIView I load another Viewcontroller (vc2).
Now the button interactions on vc2 are no longer processed. I've added new buttons and methods as a sanity check and they are not getting the press signals either. Made sure they were all connected up in the XIB and they are.
Has anybody come across this before and know the solution?
Many Thanks,
C
There must be problem with your Vc2 frame.
Try to set frame of your Vc2 manually like below code.
UIStoryboard *sb = [UIStoryboard storyboardWithName:#"Main" bundle:NULL];
SecondVC *Vc = [sb instantiateViewControllerWithIdentifier:#"idSecondVC"];
Vc.view.frame =CGRectMake(0, 0, self.containerVw.frame.size.width,self.containerVw.frame.size.height);
[self.containerVw addSubview:Vc.view];
[self addChildViewController:Vc];//adding your Vc2 as a childViewController
containerVw -> Your UIView of Vc1 in which you are adding your Vc2 as a subview.
I'm building my app using storyboard.so I can open another view controller when button preesed,by dragging.and then I can select presentation= over current context for the segue in storyboard.But what I want is to do this programmatically.I found an answer,but it says it will work for only ipads.I'm building an universal app, so I want to work it for all devices.
Is this possible.
And how can I do that.
in my first view controller
UIStoryboard *story = [UIStoryboard storyboardWithName:#"Main" bundle:[NSBundle mainBundle]];
UIViewController *middleViewController = [story instantiateViewControllerWithIdentifier:#"FlightMiddleViewController"];
and in my second view controller, viewDidLoad method I put
self.modalPresentationStyle = UIModalPresentationOverCurrentContext;
it works for a while.that means it transparent for while and then screen black.I don't know why is that.
it is working for iphone also with ios 9 >=
this is what you want to do.
in your first view controller, before you set up which view should present,
- (IBAction)searchNowAction:(id)sender {
UIStoryboard *story = [UIStoryboard storyboardWithName:#"Main" bundle:[NSBundle mainBundle]];
UIViewController *secondViewController = [story instantiateViewControllerWithIdentifier:#"secondviewControllerSBname"];
secondViewController.modalPresentationStyle = UIModalPresentationOverFullScreen;
secondViewController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentViewController:secondViewController animated:YES completion:nil];
}
this works fine for iphones also.
You need to set following property before presenting.
self.modalPresentationStyle = UIModalPresentationStyle.OverCurrentContext
Also set definesPresentationContext property of parent controller to true
Yes it will work only for iPad, as modal presentations and popover controllers are only supported in iPad.
Actually, it's not that hard to do OverCurrentContext presentation style on iPhone. Have a look at UIViewController custom transition, which was introduced in iOS 7. You will find out how to do it.
For anyone that was doning performSegue(.. programmatically
In my case I was having a modal that present a button. taping the button should push a new viewController, but it get push in fullScreen even if Im inside a modal
So after little search I found out that I was setting in storyBoard in xcode:
Presentation => fullScreen. So then I had to change is to Current Context
I want to put a view controller inside a scroll view.
I think I can do it with something like:
MyViewController *vc = [[MyViewController alloc] initWithNibName:#"MyViewController" bundle:nil];
[scrollView addSubview:vc];
What I don't understand is how to specify my nib name correctly, because I have an interface built which I want to use but it is one of multiple views appearing in my main storyboard.
You cannot add a viewController as a subview. You can add a childViewController and the viewController's view as a subview. But you should probably read up more on how Objective-C and iOS works.
We are working on splitting our main storyboard into smaller ones so that it makes source control merging easier. Any ideas on what the right approach is to load a new storyboard from a UITabBar?
Here's what we have so far in our custom subclassed UITabBarController:
UITabBarItem *cardsTabItem = [self.tabBar.items objectAtIndex:kTabBarIndexCards];
cardsTabItem.image = [[UIImage imageNamed:#"navCardsOff"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
cardsTabItem.selectedImage = [[UIImage imageNamed:#"navCardsOn"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
cardsTabItem.imageInsets = UIEdgeInsetsMake(-5, 0, 5, 0);
cardsTabItem.titlePositionAdjustment = UIOffsetMake(0, -5);
I've done the same thing before, but with a UITabBarController. In that case we had a storyboard for each of the tab buttons, even though one of the storyboards only had 1 view controller in it. I think wether you're using a UITabBarController or responding to the tab bar delegate the answer is the same. For each button clicked make the determination of which storyboard the view controller you want to load is in:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"leftButtonStoryboard" bundle:[NSBundle mainBundle]];
UIViewController *vc = [storyboard instantiateInitialViewController];
//or
UIStoryboard *otherVC = [storyboard instantiateViewControllerWithIdentifier:#"CameraViewController"];
Then you can present it, push it, or whatever.
In my case since I was using a UITabBarController this was all done during initialization of the controller for all the different buttons.
It will most likely come in handy to by default name all of the different view controller your using in your storyboard (the storyboard id), I usually name them after the viewController class so I don't have to remember what I called it.
I would also recommend that you avoid using the self.storyboard property when trying to instantiate another view controller because you might end up with a situation where a controller is shared between tabs. Being explicit with which storyboard you're loading a controller from can help with readability and avoidance of bugs.
Edit - a more concrete example:
What you need to do is set the viewControllers property of your UITabViewController, I do this in its init method. For example
- (id)initWithCoder:(NSCoder *)aDecoder {
if (self = [super initWithCoder:aDecoder]) {
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:#"Main" bundle:[NSBundle mainBundle]];
UIViewController *one = [mainStoryboard instantiateViewControllerWithIdentifier:#"VC1"];
UIViewController *two = [mainStoryboard instantiateViewControllerWithIdentifier:#"VC2"];
self.viewControllers = #[one,two];
}
return self;
}
You can use this technique if your writing it in code itself or if you're using a storyboard. Beware that if you have other view controllers already hooked up via the storyboard you'll loose then unless you instantiate them there as well. You can also use the setViewControllers: animated: method as well.
The code for creating the custom tab bar items (the buttons at the bottom) should probably go within the individual view controllers and be assigned to its tabBarItem property. The UITabBarController will use that property to create the correctly styled button. If you don't provide the property you get the default buttons starting from 1.
There are two views in my application.
After launching the app I switch the view with button like this:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Storyboard" bundle:[NSBundle mainBundle]];
UIViewController *view = [storyboard instantiateViewControllerWithIdentifier:#"view_a"];
[self presentViewController:view_a animated:NO completion:nil];
But whenever i switch the view the code above initialize the view.
I want to maintain previous status of the view.
How can I solve this problem?
instantiateViewControllerWithIdentifier: always returns a new instance of an UIViewController.
You need to keep a reference to a previous one if you don't want to create it over and over.
On an iPad this will present the second view modally, as dictated by the views modalTransitionStyle. So there you could get back to the original by calling dismissViewControllerAnimated:completion: on the new ViewController.
On the iPhone you can use a UINavigationController in your storyboard to push and then pop the secondViewController.
As long as you are using the storyboard, you can set up the transition there and the perform it using - performSegueWithIdentifier:sender: from your button. Or for that matter you can connect the segue directly to your button in which case the transition will be performed without additional code.