Note that there are some explanatory texts on larger screens.

plurals
  1. POCocoa NSView in NSTableView Cell
    primarykey
    data
    text
    <p>I'm new to cocoa and I'm getting frustrated, I've spent almost half the day trying to find out how to add an NSView to a NSTableView cell, but I haven't found a nice guide that can help me do what I would like to achieve, maybe someone can have a look at what I've tried and tell me why it's not working and how I could get it to work...</p> <pre><code>-(NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row{ NSTableCellView *view = [tableView makeViewWithIdentifier:@"MyView" owner:self]; NSTextField *textfield = [[NSTextField alloc]initWithFrame:NSMakeRect(0, 0, 100, 30)]; [textfield setStringValue:predictate_search[row]]; [textfield setBackgroundColor:[NSColor redColor]]; [view addSubview:textfield]; [view setNeedsDisplay:YES]; return view; } </code></pre> <p>What I would like to achieve is to have two NSTextFields above each other and the table cell to have a custom background. The above is me just trying to get one NSTextField to work, but with no luck...</p> <p>The NSTableView is being created programmatically: </p> <pre><code>NSScrollView *scrollView = [[NSScrollView alloc]initWithFrame:bg]; [scrollView setHasVerticalScroller:YES]; [self addSubview:scrollView]; search_results = [[NSTableView alloc]initWithFrame:bg]; NSTableColumn *column = [[NSTableColumn alloc] initWithIdentifier:@"id"]; [[column headerCell] setStringValue:@"Cities"]; [column setWidth:1000.0]; [search_results addTableColumn:column]; [search_results setDelegate:(id)self]; [search_results setDataSource:(id)self]; [search_results reloadData]; [scrollView setDocumentView:search_results]; </code></pre> <p>I'm slightly confused what to put for the <code>makeViewWithIdentifier:</code>, I've watched the <a href="https://developer.apple.com/videos/wwdc/2011/" rel="noreferrer">WWDC 2011</a> video on NSTableViews but I'm still not really sure.</p> <p>If you require more information please ask</p> <p>Thanks</p> <p><strong>EDIT</strong> After first answer:</p> <pre><code>-(NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row{ NSTableCellView *view = [tableView makeViewWithIdentifier:[tableColumn identifier] owner:self]; if(view == nil){ NSTableCellView *view = [[NSTableCellView alloc]initWithFrame:[tableView frame]]; view.identifier = [tableColumn identifier]; } NSTextField *textfield = [[NSTextField alloc]initWithFrame:NSMakeRect(0, 0, 100, 30)]; [textfield setStringValue:predictate_search[row]]; [textfield setBackgroundColor:[NSColor redColor]]; [view addSubview:textfield]; [view setNeedsDisplay:YES]; return view; </code></pre> <p>}</p> <p>However it is still not working?</p>
    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.
 

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