在我的项目中,我有一个带有自定义单元格 SearchCell 的 UITableView。然而,单元格作为空值返回,并且会使应用程序崩溃。如果我选择捕获空异常并分配/初始化一个新单元格,它会显示为空白。这是以下代码:
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
//return self.workingDatabase.count; This was causing an error for some reason, not too sure
return 1; //using 1 just for debugging
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"InfoCell";
SearchCell *cell = (SearchCell *)[tableView dequeueReusableCellWithIdentifier: CellIdentifier];
/*
if(cell == nil)
{
cell = [[SearchCell alloc] init];
}*/
// Configure the cell...
Record *record = [self.workingDatabase objectAtIndex:indexPath.row];
//set the content
cell.myName.text = record.ABName;
cell.myTarget.text = record.ABTarget;
cell.myVendor.text = record.ABVendor;
cell.myCatNumber.text = record.ABCatNumber;
cell.myClonality.text = record.ABClonality;
cell.myOrganism.text = record.ABSourceOrg;
return cell;
}