ios - Custom cell not loading button background image -


i have created custom cell using code below. have added rounded button loaded correctly when cellforrowatindexpath function called, images not loaded. thing can see in tableview circle buttons without image in it.

can me find problem is? thanks

customcell.h

@interface customcell : uitableviewcell {     uibutton *profilephoto; }  @property (nonatomic, retain) iboutlet uibutton *profilephoto;  @end 

customcell

- (void)layoutsubviews {      [super layoutsubviews];      profilephoto = [uibutton buttonwithtype:uibuttontypecustom];     uicolor  *bordercolor = [uicolor redcolor];      profilephoto.frame = cgrectmake(5.0, 8.0, 60.0, 60.0);     profilephoto.clipstobounds = yes;     profilephoto.layer.cornerradius = 30;     profilephoto.layer.bordercolor = bordercolor.cgcolor;     profilephoto.layer.borderwidth= 1.5f;     profilephoto.backgroundcolor = [uicolor clearcolor];      [self.contentview addsubview: profilephoto]; } 

cellforrowatindexpath

- (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath {      customcell *cell = [tableview dequeuereusablecellwithidentifier:@"cell"];      if (cell == nil) {         cell = [[customcell alloc] initwithstyle:uitableviewcellstyledefault reuseidentifier:@"cell"];     }      // set cell     switch (indexpath.row) {          case 0:             [cell.profilephoto setbackgroundimage:[uiimage imagenamed:@"nick.png"] forstate:uicontrolstatenormal];             break;          case 1:             [cell.profilephoto setbackgroundimage:[uiimage imagenamed:@"michael.png"] forstate:uicontrolstatenormal];             break;          default:             break;      }     return cell; } 

try this:

customcell

- (id)initwithstyle:(uitableviewcellstyle)style reuseidentifier:(nsstring *)reuseidentifier {     self = [super initwithstyle:style reuseidentifier:reuseidentifier];     if (self) {        profilephoto = [uibutton buttonwithtype:uibuttontypecustom];        uicolor  *bordercolor = [uicolor redcolor];        profilephoto.clipstobounds = yes;        profilephoto.layer.cornerradius = 30;        profilephoto.layer.bordercolor = bordercolor.cgcolor;        profilephoto.layer.borderwidth= 1.5f;        profilephoto.backgroundcolor = [uicolor clearcolor];        [self.contentview addsubview: profilephoto];     } }  - (void)layoutsubviews {      [super layoutsubviews];     profilephoto.frame = cgrectmake(5.0, 8.0, 60.0, 60.0); } 

in cellforrowatindexpath, profilephoto must nil first time. because cell layoutsubviews called later init profilephoto.

and commented, scroll reuse cell have call layoutsubviews cell have profilephoto object , image set in cellforrowatindexpath can seen after scroll.


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

How to get multiresult with multicondition in Sql Server -