2014-12-09 58 views
-1

你好傢伙我是新的iOS。我嘗試解決belove代碼中的錯誤。 每件事情都很好,但是當我嘗試搜索的時候,我們得到的是單元格零。我使用自定義單元格。我在filterDict bt cell中獲取數據是無顯示。 plz幫助我UIsearch酒吧顯示器在表視圖中使用

- (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

嘗試下面的代碼,

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    TableCell *cell = [self.tableView dequeueReusableCellWithIdentifier: CellIdentifier]; 

    // do your thing 

    return cell; 
}