views:

266

answers:

3

Running through an iPhone SDK book and one of the examples has me creating a table and then later adding a UISegmentedControl to the table for sorting.

I dutifully did this in IB, and it looks great:

IB Screenshot

When I run it in the simulator or my phone, it's totally squished:

Squished

The buttons work perfectly, it's just they are not sizing according to their content. Any ideas what's going wrong?

Here's the attributes I have set:

Attributes

+1  A: 

You could try explicitly setting the width of each of the segmented control's components. Click the Size tab at the top of the inspector and set the width for each component.

Chris Gummer
+1  A: 

I experienced the same issue once. The problem was that the UINavigationController's view was not the top-level view in the hierarchy (it was not added to UIWindow directly), but it was added as a subview to another view controller's view instead. It's just a guess, maybe that's your problem, too (or that there are more than one visible view controllers).

gyim
I'm still new to all this, so I'm not 100% sure I follow, but the navigation controller's view is "Loaded from RootView Controller", which is a table view.
davetron5000
Check your application delegate, it should contain a [window addSubview:] line. If its parameter is not something like "navigationController.view", then the example is bad (at least, IMHO). If that's the case, try to add navigationController.view to the window (instead of the old subview), and set its rootViewController to the view controller that has the segmented control stuff.
gyim
Ah, gotcha. Yeah, it is setup as you describe; I actually didn't touch this from what was generated from the new project.
davetron5000
+1  A: 

OK, so in attempting to implement @Chris Gummer's answer, I seem to have learned more about how the Size->View Size property panel works. The default is:

Default Sizing

and this is not a good default, it would seem. My book didn't mention needing to adjust this, so I didn't look at it. Setting the inner horizontal arrow of the box (which I guess means "fit width to available space") did the trick:

The Answer

davetron5000