iphone - Where to build custom UITableViewCell: in layoutSubviews or initWithStyle:reuseIdentifier? -
as understand, there seem 3 ways of laying out custom table view cell:
- in interface builder.
- in
layoutsubviews
. - in
initwithstyle:reuseidentifier:
.
what's difference between second , third methods? also, why not drawrect
?
p.s. i'm following chapter 9 of book pro ios table views tim duckett, we're building custom uitableviewcell
s. author shows how lay out cell in same order above, don't know whats difference between last 2 since both away ib. noticed, though, author sets frames in layoutsubviews
unlike in initwithstyle:reuseidentifier:
properties concerning of view set (e.g., background image, background color, etc.).
you should create cell subviews in
- initwithstyle: (uitableviewcellstyle) style reuseidentifier: (nsstring*) resueidentifier
and layout them in layoutsubviews. -initwithstyle:reuseidentifier
method called once @ initialization, cell may have incorrect frame @ moment.
thats why need layout in layoutsubviews
method, it's called when cell needs update layout, example, when autorotation occurs. if layout subviews in method, have valid cell's frame , correct subviews layout.
Comments
Post a Comment