我試圖讓自定義筆尖文件做UITableViewCell的子類的掛。自定義UITableViewCell:SIGABRT「loadNibNamed:」
子類的名稱是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];
上述方法。我在這裏做錯了什麼?
你能解決您self.theFreshlyLoadedCustomCellThingSetUpInIB是什麼意思?在我看到的例子中,人們或者遍歷nib的內容,或者簡單地使用objectAtIndex:0,因爲他們認爲它應該在那裏,因爲沒有別的東西應該在那裏。 – Ascendant
當然,在指向表格視圖單元格的上方(視圖控制器?)類中設置了一個出口。加載單元格時,NSBundle代碼會將該出口設置爲單元格。 –