setFrame: weirdness in UITableViewCell

  • I'm trying to use a custom view which does only one thing: drawing the rect defined by its bounds:

    - (void)drawRect:(CGRect)rect
    {
        // Drawing code
        UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:self.bounds
                                                  byRoundingCorners:UIRectCornerAllCorners
                                                        cornerRadii:CGSizeMake(4.0f, 4.0f)];
    [path setLineWidth:2.0f];
    [[UIColor darkGrayColor] set];
    [path stroke];
    }

    I have one instance added to a UITableViewCell in a storyboard and it works about right half the time. The other half of the time, the rectangle drawn is too high or too low:

    The strange thing is that when I set the frame in my code using this custom view, I print the frame right after I set it and I get this in the console:

    2013-05-08 15:26:19.602 erodr[35723:c07] Post “Test post”: locationBoxedView.frame origin: {233, 29}, size: {75, 19}

    I partially override the setFrame: method in my custom view just to print the new frame. This is what I do:

    - (void)setFrame:(CGRect)frame
    {
    [super setFrame:frame];
    NSLog(@"Frame set to %@", NSStringFromCGRect(frame));
    }

    And this is what I get in the console:

    2013-05-08 15:26:19.603 erodr[35723:c07] Frame set to {{108, 40}, {46, 22}}
    2013-05-08 15:26:19.603 erodr[35723:c07] Frame set to {{233, 18}, {75, 19}}

    I believe the first "Frame set" is called when a new instance of the tableview cell is created from the storyboard. But how is the second setFrame: call ends with setting the frame to 233, 18 when the calling code sets it to 233,29?

    -Laurent.
    --
    Laurent Daudelin
    AIM/iChat/Skype:LaurentDaudelin                 http://www.nemesys-soft.com/
    Logiciels Nemesys Software                    <laurent...>
  • I'm trying to use a custom view which does only one thing: drawing the rect defined by its bounds:

    - (void)drawRect:(CGRect)rect
    {
        // Drawing code
        UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:self.bounds
                                                  byRoundingCorners:UIRectCornerAllCorners
                                                        cornerRadii:CGSizeMake(4.0f, 4.0f)];
    [path setLineWidth:2.0f];
    [[UIColor darkGrayColor] set];
    [path stroke];
    }

    I have one instance added to a UITableViewCell in a storyboard and it works about right half the time. The other half of the time, the rectangle drawn is too high or too low:

    http://www.nemesys-soft.com/images/drawRect_problem_001.jpg

    The strange thing is that when I set the frame in my code using this custom view, I print the frame right after I set it and I get this in the console:

    2013-05-08 15:26:19.602 erodr[35723:c07] Post “Test post”: locationBoxedView.frame origin: {233, 29}, size: {75, 19}

    I partially override the setFrame: method in my custom view just to print the new frame. This is what I do:

    - (void)setFrame:(CGRect)frame
    {
    [super setFrame:frame];
    NSLog(@"Frame set to %@", NSStringFromCGRect(frame));
    }

    And this is what I get in the console:

    2013-05-08 15:26:19.603 erodr[35723:c07] Frame set to {{108, 40}, {46, 22}}
    2013-05-08 15:26:19.603 erodr[35723:c07] Frame set to {{233, 18}, {75, 19}}

    I believe the first "Frame set" is called when a new instance of the tableview cell is created from the storyboard. But how is the second setFrame: call ends with setting the frame to 233, 18 when the calling code sets it to 233,29?

    Anybody has any clue? The other thing I don't understand is why the timestamp on the call to setFrame: is 15:26:19.602 while the implementation of setFrame: is at 15:26:19.603. The printing of the call is *after* the call to setFrame: (actually, it's more like self.mycustomview.frame = CGRectMake(…).

    Thanks in advance for any info.

    -Laurent.
    --
    Laurent Daudelin
    AIM/iChat/Skype:LaurentDaudelin                 http://www.nemesys-soft.com/
    Logiciels Nemesys Software                    <laurent...>
previous month may 2013 next month
MTWTFSS
    1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31    
Go to today