我想用XIB作为NSTableCellView的子类。我是MAC OS编程方面的新手。
这就是我所做的:
- (NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row {
if (tableView == self.tableVSurah) {
CustomCell *cell;
cell = [[CustomCell alloc] initWithFrame:CGRectMake(0, 0, 302, 52)];
cell.txtTName.stringValue = [[arrData objectAtIndex:row] valueForKey:@"tname"];
return cell;
}
return nil;
}其中CustomCell是NSTableCellView。
虽然我很擅长iOS,但我使用下面的代码来获取特定UITableViewCell的.xib。下面的代码是用UITableView子类编写的。
+ (CustomCell *)cellFromNibNamed:(NSString *)nibName {
NSArray *nibContents = [[NSBundle mainBundle] loadNibNamed:nibName owner:self options:NULL];
NSEnumerator *nibEnumerator = [nibContents objectEnumerator];
CustomCell *xibBasedCell = nil;
NSObject* nibItem = nil;
while ((nibItem = [nibEnumerator nextObject]) != nil) {
if ([nibItem isKindOfClass:[CustomCell class]]) {
xibBasedCell = (CustomCell *)nibItem;
break;
}
}
return xibBasedCell;
}对于Mac,我们没有[[NSBundle mainBundle] loadNibNamed:nibName owner:self options:NULL];方法。
如何在我的NSTableView中加载特定的xib?
发布于 2013-10-16 19:18:06
在mac中,我们有这样的API:
- (BOOL)loadNibNamed:(NSString *)nibName owner:(id)owner
topLevelObjects:(NSArray **)topLevelObjectshttps://stackoverflow.com/questions/19401640
复制相似问题