I want to resize a UIViewController in the storyboard so I can use its UIViewController as a popover view.
On most sites I can read that the actions are:
drag a UIViewController in the storyboard
put a UIView on it
set the attribute on freeform and resize
But in my iOS 5.1 this does not work, even with a new project with only one UIViewController.
What did I forget in the procedure?
We follow the following steps to achieve the same:
Drag a UIViewController (this takes a UIView along with it, so no need to add another UIView unless you need more)
Select UIViewController on StoryBoard and set size property to Freeform
Select the UIView and set the height and width values.
If this doesn't help, you might want to delete the UIView that comes with the UIViewController, add a fresh UIView and repeat #2, and #3 above.
Drag a UIViewController
2 .Select UIViewController on StoryBoard and set size property to Freeform
select UIViewController on storyboard Enable user preferred explicit size in Content size in attributes inspector
You need to take off "Resize View from NIB" in IB attributes tab.
Related
i have a TabBar with 5 ViewControllers. i am using that array of tabBarController to populating a SideBarMenu like in Facebook app.
When i use a viewController to set as RootViewController of UINavigationController, then this viewController gets removed from the array [self.tabBarController viewControllers].
Why is this happening and how can i prevent this?
return [[UINavigationController alloc] initWithRootViewController:
[[self.tabBarController viewControllers] objectAtIndex:0]];
the viewController at objectIndex 0 gets removed and the [self.tabbarcontroller viewControllers] is returning only 4 viewControllers.
A UIViewController can only have one parent. When you add the view controller from the tab bar to the navigation controller, the navigation controller detached the view controller from its previous parent and attaches it to itself. For more information about why this happens, read the Implementing a Container View Controller section of the UIViewController documentation.
I have a problem trying to relocate a UILabel when loading a View. I can move the label if I run this code
lTarget.frame = CGRectOffset(lTarget.frame, 0.0f, -75.0f);
from for example a button action, it works properly. But where should I put this code if I want it to be called on the view load?, I tried viewDidLoad and viewWillAppear but this doesn't work.
I need to relocate this label because I want a different layout for the 3.5 inch screen.
Any idea?
If you are using a xib or storyboard with Autolayout enabled, it will cause your view size and position to be recalculated between the calls to viewWillAppear: and viewDidAppear:.
You should be able to move your code to viewDidAppear: or turn off Autolayout.
I got a very interesting problem here. My iPhone app has an UITabbarController as rootViewController in the AppDelegate.
If the app is opened the first time, it must be configured basically. For this purpose I create an UINavigationController and tell the tabbarController to present it modally:
firstRun = [[firstRunViewController alloc] init];
navCtrl = [[UINavigationController alloc] initWithRootViewController:firstRun];
[[self tabBarController] presentModalViewController:navCtrl animated:NO];
When the configuration is done, I'd like to get rid of the firstRunViewController. I'm using this technique very often, using -dismissModalViewControllerAnimated:.
But in this constellation this doesn't work. It doesn't matter from what controller I'm calling the dismiss.
I tried it via the tabbarController, the rootViewController, the currently active viewController, of cause self and several other controllers.
EVERY TIME I call -dismissModalViewControllerAnimated: I get this exception:
'UIViewControllerHierarchyInconsistency', reason: 'presentedViewController for controller is itself on dismiss for: <UINavigationController:…
Can anybody help? Thanks in advance, with kind regards, Julian
EDIT
In my AppDelegate I'm using a UITabbarController as rootViewController for the main window:
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
Then I'm creating an UINavigationController and tell the UITabbarController to present the modalViewController:
UINavigationController *navCtrl = [[UINavigationController alloc] initWithRootViewController:firstRun];
[[self tabBarController] presentModalViewController:navCtrl animated:NO];
When I now call -dismissModalViewControllerAnimated: on the firstViewController I'm getting the error from above.
In my opinion you are abusing UITabbarController. This class, even though a subclass of UIViewController, does not really use much of the UIViewController infrastructure.
What you want is a slight extension of what you have now. Create a new UIViewController subclass in your appDelegate, and add it as the single object to an array, and set the tabBar's viewControllers to this array. Set your subclass' hidesBottomBarWhenPushed to YES so it hides the tab bar when it becomes visible.
Now your app will launch and your UIViewController subclass will become the frontmost view. You can make this view the one you wanted to present modally, or you can present that view from your subclass using some kind of animation. Oh, and if you use the launch view as the background image for your subclass, you can really make this a smooth transition - I do this now.
When your modal view is done, then you can instantiate whatever views you want to then display, and set the UITabBarController to use those views with tabBarController.viewControllers (or the animated version). Poof, you UIViewController will get replaces (and under ARC just disappear).
I don't have a chance to test my hypothesis, but I suspect that this issue could depend on the fact that you are presenting the modal view too early, whereby too early means before the main window has had the chance to set up the tab bar controller. So, I would suggest this changes:
create a method to instantiate your navigation controller:
- (void)initializeAndPresentNavigationController {
UINavigationController *navCtrl = [[UINavigationController alloc] initWithRootViewController:firstRun];
[[self tabBarController] presentModalViewController:navCtrl animated:NO];
}
instead of presenting the navigation controller directly from appDidFinishLaunching, call the above method asynchronously:
[self performSelector:#selector(initializeAndPresentNavigationController) withObject:nil afterDelay:0.0];
Here the trick of calling the method as I do in 2 is that the call to initializeAndPresentNavigationController will be simply pushed on the main loop, and executed after your app has had the possibility to build its initial UI.
Hope it works for you.
I finally found the answer myself!
I just couldn't see the wood for the trees! I'm quite happy right now! :)
I did really silly things: In the last viewController of the setup viewControllers I had to change the tabars viewControllers corresponding to whether the user is administrator or not. So I did:
appDelegate.tabBarController.viewControllers = [NSArray arrayWithObjects:appDelegate.readState,
appDelegate.navCtrl,
appDelegate.settings, nil];
You can see that I was adding the AppDelegate's "navCtrl" to the tabbar's viewControllers. So I was trying to dismiss a viewController I just added to the parentViewControllers (UITabbarController) sub-controllers.
Dismissing something I want to present just in the same moment is NOT advisable! :))
I have this a simple question: How do I resize a UIViewController's view from a custom UINavigationController, since it's not working to simply set it's frame.
I have tried to, in my UIViewControllercategory, override setFrame of all UIViews, which didn't go well...
In a tableViewController I know I can set the tableview's contentInset, but that doesn't really help me here.
I think you can add another view to your UIViewController 's view's subviews. Then change the frame of this internal view is easy.
I've got a UIViewController that has a modal window which I'd like to present over the entire interface, including the UITabBar.
My application hierarchy is this:
UITabBarController (A) ->
UIViewController (B) ->
UINavigationController (C) ->
UIViewController (D) ->
UIViewController (my modal view)
When I call presentModalViewController on D, the modal view is presented but underneath the UITabBar, or should I say, the UITabBar is still shown.
I've tried setting the hidesBottomBarWhenPushed property to YES on the modal view controller, but to no avail.
Any ideas on why this isn't working for me?
The modal ViewController needs to be a direct child of the TabBarController in order to do what you want.
in ViewController "D", instead of :
[self presentModalViewController:...];
do:
[tabBarController presentModalViewController:...];
how you maintain a reference to the TabBarController is up to you.