Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here are the steps to make a single column tableview where the column can have row(s) that are section headings (NSTextFieldCells) followed by rows that are checkboxes (NSButtonCells) having descriptive titles. Similar to a listbox in MS MFC. To be compatible with older versions of OS X it needs to be a Cell based tableview:</p> <ol> <li>Using IB drag a tableView control into the Application Window. In the Attributes inspector set Content Mode as "Cell Based", and Columns to 1.</li> <li>Using IB drag a "Check Box Cell" control from the Object Library into the Application Window's column. (note: this step probably can be omitted since in the example code shown below, the cell type is being set explicitly to be either a NSButtonCell (checkbox) or NSTextFieldCell). If one needs to expand this example to use multiple columns, then probably want to set the Identifier for the NSTableColumn(s) in IB's Identity Inspector, in order that in the code one can filter by column/row instead of only by row (i.e. inside of the method objectValueForTableColumn).</li> <li>Set the TableView's datasource and delegate to be the auto generated App Delegate object (in this case ApplicationAppDelegate.h). Do this by opening IB, and using the "Connection Inspector" click and drag from the datasource circle connection icon to the "App Delegate" object icon in the IB panel that shows objects that are loaded from the NIB such as controls, controllers etc.(icon for App Delegate is a blue cube). Do the same click and drag operation with the delegate circle icon. </li> <li>Open the Assistant Editor, with the App Delegate's .h file showing in the left vertical pane and the IB view of the Table View in the right vertical pane. Select on the TableView control and create an IB outlet named "tableView" by holding the control key and dragging from the TableView Control to the section of the .h file where properties are listed.</li> <li>Declare a NSMutableArray variable in the .h file. It should look like the following (Note: there has been added NSTableViewDataSource as a supported protocol of ApplicationAppDelegate):</li> </ol> <hr> <pre><code>#import &lt;Cocoa/Cocoa.h&gt; @interface ApplicationAppDelegate : NSObject &lt;NSApplicationDelegate,NSTableViewDataSource&gt; { NSMutableArray *state; } @property (assign) IBOutlet NSWindow *window; @property (weak) IBOutlet NSTableView *tableView; @end </code></pre> <hr> <p>6 . Add the following functions to the App Delegate implementation file (.m):</p> <hr> <pre><code>#import "ApplicationAppDelegate.h" @implementation ApplicationAppDelegate - (void)applicationDidFinishLaunching:(NSNotification *)aNotification { state = [[NSMutableArray alloc]initWithObjects:@"Section Heading:",@0,@1, nil];//Note: values passed to NSButtonCells should be 0 or 1 or YES or NO, and the state passed to NSTextFieldCell is a NSString [self.tableView reloadData]; } - (NSInteger)numberOfRowsInTableView:(NSTableView *)tableView { return [state count]; } - (id)tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row { NSButtonCell * cell =[[NSButtonCell alloc]init]; [cell setButtonType:NSSwitchButton]; if (row == 0) { [tableColumn setDataCell:[[NSTextFieldCell alloc]init]]; } else if (row == 1) { [tableColumn setDataCell:cell]; [[tableColumn dataCell]setTitle:@"title row1"]; } else if (row == 2) { [tableColumn setDataCell:cell]; [[tableColumn dataCell]setTitle:@"title row2"]; } return [state objectAtIndex:row]; } - (void)tableView:(NSTableView *)tableView setObjectValue:(id)value forTableColumn:(NSTableColumn *)column row:(NSInteger)row { [state replaceObjectAtIndex:row withObject:value]; [tableView reloadData]; } @end </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload