LoginSignup
2
3

More than 5 years have passed since last update.

NSTableView に CustomView を表示させる

Last updated at Posted at 2015-07-25

メモ。

NSTableView にデータを表示させる方法
http://rakuishi.com/archives/5535/
上記はdataSourceから文字を返すやり方。でも、たいていの人がやりたいのはCellを返すということだと思う。
任意のViewを返すのは、iPhoneと同じくdelegateから返す。
iPhoneと違うところは、カラムがあるところ。

下記の手順で設定する。

  • カラム単位でidentifierがあるので、こいつを設定する。
    Screen Shot 2015-07-26 at 6.15.32 AM.png

  • delegate先でregisterNib:forIdentifier:する。

        NSNib *cellNib = [[NSNib alloc] initWithNibNamed:@"MECategoryTableViewCell" bundle:nil];
        [self.categoryTableView registerNib:cellNib forIdentifier:@"category_"];

        self.categoryTableView.dataSource = self;
        self.categoryTableView.delegate = self;
  • viewForTableColumn内でmakeViewWithIdentifier:する。
- (NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row {
    MECategoryTableViewCell *cell = [tableView makeViewWithIdentifier:@"category_" owner:self];
    [cell.textField setStringValue:[MECategory existCategories][row]];
    return cell;
}
2
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
3