UISegmentedControl autoresizingMask not working - iphone

I placed a UISegmentedControl programmatically on the screen (stand-alone, not as part of a navigation bar) and set its autoresizingMask to UIViewAutoresizingFlexibleLeftMargin because I want it to stick to the right.
However, when I rotate the screen the control stays in its original position and does not move to the right (or anywhere else for that matter).
I also tried all other possible values (and some combinations) for the autoresizingMask, but the thing doesn't move at all.
Other elements on the screen with the same setting move correctly.
I do not have a XIB for this view controller, but I tried to place a similar segmented control temporarily in another XIB, and when I set the struts correctly it did move as expected.
What am I doing wrong?

In your view controller's viewDidLoad method place the following log statement:
NSLog(#"%#", [self.view recursiveDescription]);
This will log out your view controller's view hierarchy. If it's not clear from the log where the issue is, then please add the log to your question so we can help further.

Related

Load a view controller created inside a storyboard as a subview (into a part of the screen) of another view controller

I am currently developing as app for iPad. And I need to create a tabbar. The problem is that, for design purposes, I need the tabbar to be on the top half of the screen and not on the bottom as it is on the default tabbar controller.
Once the tabbar is on top I want that when a button is touched, the subview bellow the tab is changed. Furthermore, the subview that should be loaded was alson designed inside the storyboard. The following sketch shows what I want it to look like:
On my research I found a solution (here) for putting the tabbar on top. Now my problem is on loading a subview bellow it.
I tried it with [self.view addsubview:theNameOfTheViewCreatedINStoryboad.view] but the application simply hangs when I press the button.
I think that is because I am not specifying anywhere what should be the dimension of the new view or where on the scree should it be placed. The reason for that is because I do not know where it should be done.
Can anyone give me some lights on this matter? Is the referred approach the best one for putting a tabbar on top? How can I solve the subview problem?
Glad to see you are using a toolBar and not a tabBar. Even better would be to create a custom content view controller.
You should be looking into using containment:
UIViewController containment
How does View Controller Containment work in iOS 5?
positioning UIViewController containment children
check out the docs

View size changing after viewWillAppear

In my iPhone application, which is based on a NavigationController, I have some elements a, b, c subviews of another view X. When I push the controller to get this view, on viewWillAppear, I adjust the size and position of a, b, and c according to the size of X in order to properly handle device orientation. The problem is that the size of X is being changed after viewWillAppear has been called. I subclassed X and wrote a setFrame method in order to set a breakpoint and try to find the cause. Below are links to images (I could not post the image directly due to lack of points) showing the break at viewWillAppear, and the break at setFrame after viewWillAppear with the callstack. I need help to find out why the size of X is being changed this way. Thanks.
At viewWillAppear:
http://img718.imageshack.us/img718/9898/viewwillappearbreak.th.png
After viewWillAppear in break at subclassed setFrame:
http://img703.imageshack.us/img703/7995/afterviewwillappear.th.png
Thanks in advance. ( I hope the images will show up correctly).
Thanks for all the responses with the limited information I provided. I finally found the cause of the problem. My nib file included a toolbar (which I guess is a bad thing to do if you are using a navigation controller) and I was also calling
setToolbarHidden: NO
on my Navigation Controller. I'm new to iPhone programming, and thought that the toolbar in the nib file would somehow be shown as the navigation view toolbar. It seems this is not the case. My understanding of why the problem was happening, is:
The view got loaded with a toolbar from the nib, and the navigation controller had a visible toolbar, so my X view height was 328. (the height of 2 toolbars were being subtracted when adjusting to the screen size. the one from the navigator controller and the one in the view).
After viewWillAppear, the navigation controller code apparently found the 2 toolbars, so it decided to hide the one in the navigation controller, increasing my X view height by 44 (to 372).
I removed the toolbar from the nib file, and added the toolbar items to the navigation controller toolbar by calling
setToolbarItems
The height of the frame remained unchanged after viewWillAppear.
Thanks for the responses. I hope this comments will benefit someone else facing the same issue.

iPhone make toolbar visible in UITableView

I have a UITableView has a subview of a UIView and I've added a toolbar on top of the UITableView so it should look like this:
However when I actually run it, it looks like this:
So for some reason the UIToolBar isn't showing up. I really don't know why, is anybody able to figure this one out? Thanks in advance.
EDIT: I've changed the simulated metrics like suggested and it still does not show up:
EDIT2: Here is a list of objects as requested by Raixer.
Alright. I have a similar setup in my app so I will show you what I did.
I setup a tab bar controller with navigation controllers in each tab (this gives me the navigation bar automatically that is why I use it). If you notice the View on the first tab is being loaded from another nib (that is what I am assuming you are doing). I did this by changing the view's class to my own view controller and then setting the name of the NIB file to load in the Inspector like this:
(source: minus.com)
Then in my other nib file I only have this:
I hope this helps.
That's because you configured your nib file without counting with the height of the Tab bar.
The toolbar's height is 49 pixels. So when the view appears all your elements are moved 49 pixels up.
You should got to IB, open your View, go to Attributes Inspector, and in simulated metrics select Tab bar for Bottom Bar.
I doubt you will succeed with this approch. UITableViewController is very picky about adding subviews to its UITableView. However, you can have your UITableView handled by a standard UIViewController (just let IB point to a custom class inheritng from UIViewController). Add the table view to the controller's view as a subview and add the toolbar to the outer view.
Then you should be able to add subviews. UITableViewController gives you some convinience and functionality. If you can live without, UIViewController is no disadvantage. If you can't, you'll have to implement it yourself.
Another alternative to get the toolbar: put your table into a UINavigationController. That one comes with a toolbar (on top).

a question about rotation when multiple views are involved

I'm a relative newcomer to cocoa & programming for the ipad.
I've built an app that has a split view controller. In the detail view is a toolbar with a button on it. When the button is pressed, the split view controller is removed from the superview, and another view is put in its place. A toolbar button on this new view removes the view and puts the split view back. Works great... except when the ipad is rotated while the second view is visible. When the user returns to the split view, it's displayed as it was before the rotation.
The split view and all the sub views are set to autoresize=yes, and return yes when they receive the autorotatetointerfaceorientation message.
I'm guessing I need to tell the split view and its sub views to resize themselves when I add it as a subview to the window.
Thanks
Chris
Please see my question concerning this matter here:
Best way to switch between UISplitViewController and other view controllers?
If you use UISplitViewController as Apple intend you to, it's quite limited.
I ended up using a strategy exactly as you mention -- i.e. remove the UISplitViewController's view from UIWindow, and replace with another, and then later switch back. I found out that the orientation change WAS handled, even if I rotated while view B was presented (B being the non-split view), then switch back to A (the split view). However, I had to do a bit of fiddling with the frame size of the uisplitview to make it work. Will update with more info later when I find it.
There's also the option of writing your own split view controller, or using someone else's reimplementation, such as this one:
http://mattgemmell.com/2010/07/31/mgsplitviewcontroller-for-ipad
UPDATE
The fiddling I did with the frame size of UISplitView can be seen in the following method in my AppDelegate. These methods are for presenting the split view controller by replacing another top level view controller under UIWindow:
- (void)removeAllWindowSubviews {
for (UIView *childView in window.subviews) {
[childView removeFromSuperview];
}
}
- (void)presentSplitView:(UISplitViewController *)vc {
[self removeAllWindowSubviews];
UIView *viewForSplitVC = vc.view;
// fix for deficiency in adding a split view controller's view in landscape mode
// and it still having a frame for portrait mode.
// 2010-10-15 added -20.0f to fix problem with toolbar in LHS VC being 20 pix too low.
viewForSplitVC.frame = CGRectMake(viewForSplitVC.frame.origin.x, viewForSplitVC.frame.origin.y,
navigationController.view.bounds.size.width, navigationController.view.bounds.size.height - 20.0f);
[window addSubview:viewForSplitVC];
}
// for removing the split view and restoring the other main VC
- (void)restoreMenu {
if (isIPad()) {
[self removeAllWindowSubviews];
[window addSubview:navigationController.view];
}
}
As I said, it's a hack, but the correcting of the frame gave me the ability to present the split VC without its frame being sometimes incorrect. And as I noted earlier, by doing this stuff, we're going outside what Apple want us to do, hence the hackery involved.
Ok, I have an idea for what might work: Don't remove the UISplitViewController's view from the view hierarchy. Instead, either put a view on top of it, set the alpha property of its view to 0 or set the hidden property of its view to YES.

Strangeness with a view controller's frame

I've created a simple application with a single view controller and removed the status bar so I can use the full height of the screen. The view controller's xib file loads perfectly well, displaying a backdrop image very nicely. I then added a custom view object which will be handling certain graphical tasks directly for me, and asked it to initialize itself with the custom view's frame rectangle. I did this in the 'viewDidLoad' method for the view controller. For some strange reason though, the view controller is reporting its frame rectangle as if the status bar were still visible, despite the fact that I hide it before creating the view controller. Can someone explain why, and maybe suggest a workaround?
-Ash
Oops, it's always the simple things isn't it? I just forgot this command:
viewHolder.wantsFullScreenLayout = YES;