开发者

UITableViewCell contentView width changes in iOS5?

On iOS < 5.0, this code for a grouped table cell of mine:

NSLog(@"%f", cell.contentView.bounds.size.width);

returns 302.

But on iOS5, the same code returns 320 (that is, including the margin of the grouped cell layout in the wi开发者_StackOverflowdth).

Is that expected behaviour?

And if so, how to I then reliable get the width of a grouped, tableview cell not including the margin?


I think this change has to do with the timing of the layout of the cell and the width of 302 is set in a viewWill* or viewDid* method when more is known about accessories, tableview style, etc.

When I ran into this I fixed it by setting the autoresizingMask property appropriately for when the contentView was adjusted to the with of 302 later in the code.

Since I was getting the bounds width so I could add a text field on the right side of the cell, simply adding:

valueTextField.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;

made it pop back to where it was before iOS5. I suspect I would get better behavior with this if the device was rotated or go in and out of edit mode but this particular tableview does not do either of these.

Hope this helps ya!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜