大家好我是iOS新手。我试着解决belove代码中的错误。 一切都工作正常,但当我尝试搜索时,我们得到的细胞为零。我使用自定义单元格。我在filterDict中得到数据bt cell是nil show。请帮助我
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"MyCell";
TableCell *cell = (TableCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[TableCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier ];
}
NSDictionary *dic;
if(tableView == self.searchDisplayController.searchResultsTableView)
{
key = [searchBarSectionFilterArray objectAtIndex:indexPath.section];
arrayDictonry = [dict valueForKey:key];
NSDictionary *filterDict = [arrayDictonry objectAtIndex:indexPath.row];
if([[filterDict valueForKey:@"digiboxStatus"]isEqualToString:@"DEAD"])
{
[cell.cellImage setBackgroundColor:[UIColor colorWithRed:245.0/255.0 green:105.0/255.0 blue:84.0/255.0 alpha:1.0]];
}
else
{
[cell.cellImage setBackgroundColor:[UIColor colorWithRed:0.0/255.0 green:166.0/255.0 blue:90.0/255.0 alpha:1.0]];
}
[cell.locationNameLable setText:[filterDict valueForKey:@"locTitle"]];
if([[filterDict objectForKey:@"lastseenStr"] isEqual:[NSNull null]] || [[filterDict objectForKey:@"lastseenStr"] isEqualToString:@""])
{
TableCell *lable;
[lable.lastSeenTimeLable setHidden:YES];
[cell.lastSeenTimeLable setText: @"Not Available"];
}
else
{
[cell.lastSeenTimeLable setText:[filterDict valueForKey:@"lastseenStr"]];
}
}
else
{
key = [dictArray objectAtIndex:indexPath.section];
arrayDictonry = [dict valueForKey:key];
dic = [arrayDictonry objectAtIndex:indexPath.row];
if([[dic valueForKey:@"digiboxStatus"]isEqualToString:@"DEAD"])
{
[cell.cellImage setBackgroundColor:[UIColor colorWithRed:245.0/255.0 green:105.0/255.0 blue:84.0/255.0 alpha:1.0]];
}
else
{
[cell.cellImage setBackgroundColor:[UIColor colorWithRed:0.0/255.0 green:166.0/255.0 blue:90.0/255.0 alpha:1.0]]; }
[cell.locationNameLable setText:[dic valueForKey:@"locTitle"]];
if([[dic objectForKey:@"lastseenStr"] isEqual:[NSNull null]] || [[dic objectForKey:@"lastseenStr"] isEqualToString:@""])
{
TableCell *lable;
[lable.lastSeenTimeLable setHidden:YES];
[cell.lastSeenTimeLable setText: @"Not Available"];
}
else
{
[cell.lastSeenTimeLable setText:[dic valueForKey:@"lastseenStr"]];
}
}
return cell;
}
答案 0 :(得分:0)
尝试以下代码,
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
TableCell *cell = [self.tableView dequeueReusableCellWithIdentifier: CellIdentifier];
// do your thing
return cell;
}