UISegmentedControl very strange problem

Discussion in 'iOS Programming' started by namanhams, Sep 16, 2010.

  1. namanhams macrumors regular

    Joined:
    Jun 3, 2009
    #1
    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.
     
  2. namanhams thread starter macrumors regular

    Joined:
    Jun 3, 2009
    #2
    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];
    
     
  3. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #3
    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];
     
  4. namanhams thread starter macrumors regular

    Joined:
    Jun 3, 2009
    #4
    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.
     
  5. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #5
    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.
     
  6. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #6

Share This Page