【发布时间】:2011-08-01 11:55:28
【问题描述】:
我正在尝试使用自定义 nib 文件来完成 UITableViewCell 的子类。
子类的名称是 MyCustomCell。 .xib 文件只有一个带有单个 UILabel“cellTitle”的 UITableViewCell,我已将它连接到 UITableViewCell 子类中的插座。
在返回单元格的 MyCustomCell 类中,我在以下行收到 SIGABRT 错误:
NSArray *nibContents = [[NSBundle mainBundle] loadNibNamed:@"View" owner:self options:NULL];
下面是 cellForRowAtIndexPath 的实现:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *kCustomCellID = @"MyCellID";
myCustomCell *cell = (myCustomCell *)[tableView dequeueReusableCellWithIdentifier:kCustomCellID];
if (cell == nil)
{
cell = (myCustomCell *)[myCustomCell cellFromNibNamed:@"myCustomCell"];
}
//TODO: Configure Cell
return cell;
}
这是 myCustomCell cellFromNibNamed 的实现:
+ (myCustomCell *)cellFromNibNamed:(NSString *)nibName
{
NSArray *nibContents = [[NSBundle mainBundle] loadNibNamed:@"View" owner:self options:NULL];
NSEnumerator *nibEnumerator = [nibContents objectEnumerator];
myCustomCell *customCell = nil;
NSObject* nibItem = nil;
while ((nibItem = [nibEnumerator nextObject]) != nil)
{
if ([nibItem isKindOfClass:[myCustomCell class]])
{
customCell = (myCustomCell *)nibItem;
break; // we have a winner
}
}
return customCell;
}
我在该行中收到 SIGABRT 错误
NSArray *nibContents = [[NSBundle mainBundle] loadNibNamed:@"View" owner:self options:NULL];
在上述方法中。我在这里做错了什么?
【问题讨论】:
标签: ios uitableview