Is it possible to design NSCell subclasses in Interface Builder?

后端 未结 10 1261
终归单人心
终归单人心 2020-12-13 15:09

I\'m trying to subclass NSCell for use in a NSTableView. The cell I want to create is fairly complicated so it would be very useful if I could design it in Interface Builder

10条回答
  •  粉色の甜心
    2020-12-13 15:50

    I do it like this:

    /* example of a silly way to load a UITableViewCell from a standalone nib */
    
    + (CEntryTableViewCell *)cell
    {
    // TODO -- this is really silly.
    NSArray *theObjects = [[NSBundle mainBundle] loadNibNamed:@"EntryTableViewCell" owner:self options:NULL];
    for (id theObject in theObjects)
        if ([theObject isKindOfClass:self])
            return(theObject);
    NSAssert(NO, @"Could not find object of class CEntryTableViewCell in nib");
    return(NULL);
    }
    

    However it isn't very efficient and if you're loading lot of data it might hurt you. Of course you should be using a reuseIdentifier which should force this code to only run a handful of times per table.

提交回复
热议问题