Multiple String Types NSTableView

I am trying to create a homework scheduler application that has two types of TableCellViews in an NSTableView based view. One type is a narrow bar, in which there is only a label of what the lower home task is intended for, and the other type is a line for entering homework. (I will include a screenshot below.)

My question is: when creating new rows in a TableView, how do you indicate which type of row you want to create? I suppose this has something to do with identifiers, but I cannot find any information on how to use them that way.

It basically looks like this:

+4
source share
1 answer

You are on the right track with identifiers. Here is how you use them.

First set up your NSTableView with specific row types (as you probably already did). In the screenshot below, I made one line with a title and description, and the other with several buttons.

Two different table rows

Then you need to configure the desired identifiers. Click the first line in Interface Builder and select Identity Inspector. Select a unique identifier for the first row. Do the same for the other.

Set the row identifier

Finally, in your implementation, create a new line of a specific type using the following code:

TableViewController.m

#pragma mark - NSTableViewDelegate - (NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row { NSTableCellView *cell; if(someCondition == YES) { cell = [self.tableView makeViewWithIdentifier:@"ButtonRow" owner:self]; } else { cell = [self.tableView makeViewWithIdentifier:@"TitleDescriptionRow" owner:self]; } return cell; } 

If you're looking for a deeper guide, check out Cocoa Programming L51 - View-Based NSTableView (YouTube video, not me).

+7
source

Source: https://habr.com/ru/post/1501181/


All Articles