objective c - NSTableView Changing Text Color for a row -
i need change following properties nstable view 1 -- change color:row color , text color when selected 2 -- change text color , each row depends upon input parameter,
for changing textcolor each row, should override delegate method willdisplaycell, have done , till now,
-- creating table ----
pmytableview = [[[customtableview alloc] initwithframe:clipviewbounds] autorelease]; nstablecolumn* firstcolumn = [[[nstablecolumn alloc] initwithidentifier:@"firstcolumn"] autorelease]; [firstcolumn setwidth:35]; [pmytableview addtablecolumn:firstcolumn]; nstablecolumn* secondcolumn = [[[nstablecolumn alloc] initwithidentifier:@"secondcolumn"] autorelease]; [secondcolumn setwidth:180]; [pmytableview addtablecolumn:secondcolumn]; [pmytableview setrowheight:30]; [self setcontacttabledisplayattribute]; [pmytableview setdatasource:self]; [scrollview setdocumentview:ponlinectview]; [pmytableview setdelegate:self] ;
--- other delegate method -------------
- (id) tableview:(nstableview *)atableview objectvaluefortablecolumn:(nstablecolumn *)atablecolumn row:(nsinteger)rowindex{ if([pcolname isequaltostring:@"secondcolumn"]) { // here there logic , proper string wanted display return @"tempstring"; } }
---- how setting text color ---
- (void)tableview:(nstableview *)atableview willdisplaycell:(id)acell fortablecolumn:(nstablecolumn *)atablecolumn row:(int)rowindex { nsstring *colname = [atablecolumn identifier]; if([colname isequaltostring:@"secondcolumn"]){ nstextfieldcell *pcell = acell; [pcell settextcolor:[nscolor bluecolor]]; } }
with above code, going exception in log, see line -[nscell settextcolor:]: unrecognized selector sent instance looks somewhere need set text field cell, how , have no idea, kindly me,
another thing is, don't need background cell, once when cell selected , might need change background or can highlight color, can same in willdisplaycell
it has been while since have done refer blog post corbin dunn when need it: cocoa: willdisplaycell delegate method of nstableview, [nscell settextcolor], , “source lists”
by way, corbin works @ apple , understand responsible nstableview. when blogs cocoa sure bookmark it.
Comments
Post a Comment