ios - Custom TableViewCell are shown white and empty in my TableView -
i have created custom tableviewcell class named optionstableviewcell , custom tableviewcontroller class named wpoptionstableviewcontroller. cells empty , white. here i've done far :
appdelegate.m :
- (bool)application:(uiapplication *)application didfinishlaunchingwithoptions:(nsdictionary *)launchoptions { self.window = [[uiwindow alloc] initwithframe:[[uiscreen mainscreen] bounds] ]; wpoptionsviewcontroller *vc = [[wpoptionsviewcontroller alloc] init] uitableview *view = vc.tableview; [view registerclass:[optionstableviewcell class] forcellreuseidentifier:@"optionstableviewcell"]; self.window.rootviewcontroller = vc; [self.window makekeyandvisible]; return yes; } optionstableviewcell.m :
- (instancetype) initwithstyle:(uitableviewcellstyle)style reuseidentifier:(nsstring *)reuseidentifier { self = [super initwithstyle:style reuseidentifier:reuseidentifier]; if ( self ) { self.selectionstyle = uitableviewcellselectionstylenone; self.textlabel.textcolor = [uicolor yellowcolor]; } return self; } - (void)setselected:(bool)selected animated:(bool)animated { [super setselected:selected animated:animated]; [self highlight:selected]; } - (void)sethighlighted:(bool)highlighted animated:(bool)animated { [super sethighlighted:highlighted animated:animated]; [self highlight:highlighted]; } - (void)highlight:(bool) highlight { uicolor *tintcolor = [uicolor whitecolor]; if ( highlight ) tintcolor = [uicolor colorwithwhite:1.0 alpha:0.6]; self.textlabel.textcolor = tintcolor; } wpoptionstableviewcontroller.m :
- (void)viewdidload { [super viewdidload]; self.tableview.delegate = self; self.tableview.datasource = self; self.tableview.backgroundcolor = [uicolor redcolor]; self.tableview.contentinset = uiedgeinsetsmake(80, 0.0, 0.0, 0.0); self.clearsselectiononviewwillappear = no; } - (nsinteger)tableview:(uitableview *)tableview numberofrowsinsection:(nsinteger)section { // return number of rows in section. return 3; } - (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath { optionstableviewcell *cell = [[optionstableviewcell alloc] initwithstyle:uitableviewcellstyledefault reuseidentifier:@"optionstableviewcell"]; if ( indexpath.row == 0 ) cell.textlabel.text = @"home"; if ( indexpath.row == 1 ) cell.textlabel.text = @"profile"; if ( indexpath.row == 2 ) cell.textlabel.text = @"settings"; return cell; } no need use dequeuereusablecellwithidentifier have 3 rows
edit: don't use xib file. problem seems in custom cell implementation can't see wrong.
this because, you're setting textcolor white in highlight method of optiontableviewcell. default,as not being highlighted, bool value of highlight no. give else condition , replace tint color black color. can see text.
uicolor *tintcolor = [uicolor blackcolor];
Comments
Post a Comment