Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

namanhams

macrumors regular
Original poster
Jun 3, 2009
153
0
I have a UITableViewController in a UINavigationController. When the user tap 1 row of the table view, then the navigation controller will push an UIViewController called A.

When A.view doesn't have any UISegmentedControl, then every works perfect.
When A.view has an UISegmentedControl, then the program hangs. It doesn't crash, it doesn't show any error. It just freezes.

I'm gonna be crazy with this problem. Please help. Thanks.
 

namanhams

macrumors regular
Original poster
Jun 3, 2009
153
0
Here's some code :


Code:
// Doesn't hang
UISegmentedControl *control = [[UISegmentedControl alloc] init];
[self.view addSubview:control];

Code:
// Hang
UISegmentedControl *control = [[UISegmentedControl alloc] init];
[control insertSegmentWithTitle:@"1" atIndex:0 animated:FALSE];
[self.view addSubview:control];
 

dejo

Moderator emeritus
Sep 2, 2004
15,982
452
The Centennial State
What happens if you try?:
Code:
UISegmentedControl *control = [[UISegmentedControl alloc] init];
[control insertSegmentWithTitle:@"1" atIndex:0 animated:FALSE];
[control insertSegmentWithTitle:@"2" atIndex:1 animated:FALSE];
[self.view addSubview:control];
 

namanhams

macrumors regular
Original poster
Jun 3, 2009
153
0
It all hangs whenever you create a UISegmentedControl with some labels.

I've just found out some hint which may be interesting :

I've created a UILabel category, which has only 1 method :
Code:
- (void) sizeToFit;

If i remove the above, every thing will works perfect.

If i include the above, then it hangs whenever i create a UISegmentedControl with some labels, although my code doesn't use the 'sizeToFit' method at all.

So i guess, the UISegmentedControl implementation actually creates a category on UILabel, which has a method that accidently has the name 'sizeToFit'. So what i did is actually redefining it.


Please correct me if i'm wrong. Thanks.
 

robbieduncan

Moderator emeritus
Jul 24, 2002
25,611
893
Harrogate
You have overridden an existing method. Unless you are intentionally overriding it and providing correct, consistent behaviour with what this is meant to do then don't override it: this is certainly going to be called to size the labels used internally by the segmented control.
 

dejo

Moderator emeritus
Sep 2, 2004
15,982
452
The Centennial State
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.