Custom Cells

Discussion in 'Mac Programming' started by Blkant, Sep 15, 2014.

  1. Blkant macrumors member

    Blkant

    Joined:
    Jul 27, 2012
    #1
    I have only recently started learning cocoa so as a warning upfront I'm pretty unfamiliar and uncomfortable with it at the moment. I apologize if I miss anything blatantly simple. :/

    I've been following a tutorial for learning how to use NSTableView bit by bit, I finally got one working, however now I want to get it working with a custom cell. I subclassed NSTableCellView (which just for temporary reference I'm calling MyCell) and created a new xib etc...

    I though that with the code I have so far from the tutorial, I could just change the class in the populating code and have it at least change which cell is being used, however I still get the exact same result even if I change all references to MyClass instead of NSTableCellView. Nothing that I've added to the xib for the new class shows up at all, instead it runs 100% identical to the NSTableCellView.

    What am I missing or not understanding here? This is the code that populates the table:

    Code:
    
    -(NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row {
        NSDictionary *flag = _tableContents[row];
        NSString *identifier = [tableColumn identifier];
        if ([identifier isEqualToString:@"MainCell"]) {
            NSTableCellView *cellView = [tableView makeViewWithIdentifier:@"MainCell" owner:self];
            [cellView.textField setStringValue:flag[@"name"]];
            [cellView.imageView setImage:flag[@"image"]];
            return cellView;
        }
        return nil;
    }
    
    
    After changing all of the NSTableCellView portions to the MyCell subclass still it works 100% the same as before, with none of the buttons etc... that I add to the new xib.
     
  2. devilofspades macrumors member

    Joined:
    Jul 20, 2011
    #2
    i would make sure in interface builder you have set your cell xib to be a subclass of "MyCell", as well as making sure the cell in your TableView references that cell and not the generic class. make sure all the items in your cell are wired up to your custom subclass in interface builder, and lastly don't forget to import your custom cell subclass.
     
  3. Blkant thread starter macrumors member

    Blkant

    Joined:
    Jul 27, 2012
    #3
    I checked that the custom view in the subclassed xib is changed to MyCell, I also verified that I have control dragged the label in the xib to the header of MyCell.

    The NSTableCellView that I dragged into the NSTableView in the MainMenu.xib was a NSTableCellView. I tried changing it to a custom class MyCell however I still get the results from the NSTableCellView.

    Do I have to drag something different into the NSTableView to use a custom cell?

    Is there something other than subclassing and dragging the label from the MyCell xib that I need to do with the MyCell? Anything I needed to implement?
     

Share This Page