iphone - Where to build custom UITableViewCell: in layoutSubviews or initWithStyle:reuseIdentifier? -


as understand, there seem 3 ways of laying out custom table view cell:

  1. in interface builder.
  2. in layoutsubviews.
  3. 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 uitableviewcells. 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

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

css - Firefox for ubuntu renders wrong colors -