cocoa - How does the NSTableView set content Mode(view-based or cell-based) by code? -


as title. how nstableview set content mode(view-based or cell-based) code?

thanks helping

nstableview defaults being cell-based, makes sense backwards compatibility. table views view-based when table view delegate implements -tableview:viewfortablecolumn:row:. can test programmatically creating table view follows:

@implementation bavappdelegate  - (void)applicationdidfinishlaunching:(nsnotification *)anotification {     nsview *contentview = self.window.contentview;     nstableview *tableview = [[nstableview alloc] initwithframe:(nsrect){{50, nsmaxy(contentview.frame) - 200}, {400, 200}}];     tableview.datasource = self;     tableview.delegate = self;     [contentview addsubview:tableview];      nstablecolumn *column = [[nstablecolumn alloc] initwithidentifier:@"column"];     column.width = 400;     [tableview addtablecolumn:column]; }  - (nsinteger)numberofrowsintableview:(nstableview *)tableview {     return 3; }  - (id)tableview:(nstableview *)tableview objectvaluefortablecolumn:(nstablecolumn *)tablecolumn row:(nsinteger)row {     return [nsstring stringwithformat:@"%ld", row]; }  //- (nsview *)tableview:(nstableview *)tableview viewfortablecolumn:(nstablecolumn *)tablecolumn row:(nsinteger)row { //    nstextfield *textfield = [[nstextfield alloc] initwithframe:(nsrect){.size = {100, 15}}]; //    textfield.stringvalue = [nsstring stringwithformat:@"%ld", row]; //    return textfield; //}  @end 

if run code delegate method commented out, cell-based table view:

enter image description here

and if uncomment delegate method, view-based table view:

enter image description here

the documentation -tableview:viewfortablecolumn:row: states that

this method required if wish use nsview objects instead of nscell objects cells within table view. cells , views can not mixed within same table view.

which hints @ being condition determines whether table view cell- or view-based.


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -