本帖最后由 jqmoab 于 2014-03-12 23:56:47 编辑

解决方案 »

  1.   


            static NSString *myCellIdentifier = @"LifeShopsList";
            LifeShopsList *cell = (LifeShopsList *)[tableView dequeueReusableCellWithIdentifier:myCellIdentifier];
            
            if (cell == nil) {
                NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"LifeShopsList" owner:nil options:nil];
                
                for(id currentObject in topLevelObjects)
                {
                    if([currentObject isKindOfClass:[LifeShopsList class]])
                    {

                        cell = (LifeShopsList *)currentObject;
                        LIFE *news;
                        if (self.nshowid) {
                            if ([indexPath row]==0) {
                                [cell.title setHidden:YES];
                                [cell.distance setHidden:YES];
                                [cell.image setHidden:YES];
                                [cell.address setHidden:YES];
                                [cell.times setHidden:YES];
                                [cell.level setHidden:YES];
                                 cell.imageally.hidden=YES;
                                 cell.lbldistancetext.hidden=YES;
                                 cell.lblleveltext.hidden=YES;
                                [self databack];
                                return cell;
                            }
                           
                            news  = [self.list objectAtIndex:[indexPath row]+2];
                        }
                        else
                        {
                            news  = [self.list objectAtIndex:[indexPath row]];
                        }
                        if ([news.ally isEqualToString:@"1"]) {
                            
                            [cell.title setFrame:CGRectMake(122, 15, 189, 21)];
                        }
                        else
                        {
                            cell.imageally.hidden=YES;
                        }
                        cell.title.text = news.name;
                        
                        cell.distance.text = news.distance;
                        cell.image.placeholderImage = [UIImage imageNamed:@"背景图.PNG"];
                        //     self.imageMidView.page = self.page;
                        if (news.imageMidURL!=nil&&![news.imageMidURL isEqualToString:@""]){
                            //  NSURL *imageUrlqr = [NSURL URLWithString:news.imageMidURL];
                            // self.imageMidView.imageURL = [NSString stringWithFormat:@"%@",imageUrlqr];
                            [cell.image setImageURL:[NSURL URLWithString:news.imageMidURL]];
                            
                        }
                        else
                        {
                            [cell.image setImage:[UIImage imageNamed:@"背景图.PNG"]];
                        }
                        cell.address.text=news.address;
                        cell.times.text=news.time;
                        switch ([news.level integerValue]) {
                            case 1:
                                [cell.level setImage:[UIImage imageNamed:@"1星.png"]];
                                break;
                            case 2:
                                [cell.level setImage:[UIImage imageNamed:@"2星.png"]];
                                break;
                            case 3:
                                [cell.level setImage:[UIImage imageNamed:@"3星.png"]];
                                break;
                            case 4:
                                [cell.level setImage:[UIImage imageNamed:@"4星.png"]];
                                break;
                            case 5:
                                [cell.level setImage:[UIImage imageNamed:@"5星.png"]];
                                break;
                            default:
                                break;
                        }
                        
                        cell.contentView.backgroundColor = [UIColor clearColor];
                        UIView *aView = [[UIView alloc] initWithFrame: cell.contentView.frame];
                        UIColor *cellColor = nil;
                        if ([[NSUserDefaults standardUserDefaults] boolForKey:@"nightMode"]){
                            
                            cell.title.textColor = [UIColor colorWithRed:164.0/255 green:165.0/255  blue:169.0/255 alpha:1.0f];
                            cell.image.alpha = 0.5;
                            cellColor = [UIColor colorWithRed:34.0/255 green:34.0/255  blue:34.0/255 alpha:1.0f];
                            // tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
                            self.separatorImageView.image = [UIImage imageNamed:@"页面分割线.png"];
                            
                        }else{
                            cell.title.textColor = [UIColor blackColor];
                            cell.image.alpha = 1;
                            cellColor = [UIColor colorWithRed:221.0/255 green:221.0/255  blue:221.0/255 alpha:1.0f];
                            self.separatorImageView.image = [UIImage imageNamed:@"页面分割线2.png"];
                            //tableView.separatorStyle = UITableViewCellSelectionStyleGray;
                        }
                        
                        aView.backgroundColor = cellColor;
                        cell.selectedBackgroundView = aView;  // 设置选中后cell的背景颜色
                        break;
                    }
                }
                
                
            }
            return cell;这是我的一段代码,注意看红色部分
      

  2.   

    self.commentsCell = [[[NSBundle mainBundle] loadNibNamed:@"HomeNewsTableCell" owner:self options:nil] lastObject];
    也可以这么写
      

  3.   

    您的代码好复杂呵,阅读后我的理解是,您的代码意思是如果是第0行,则隐藏那些控件,其他行则显示,这些都是在一个xib内进行的。您的xib只有一个,我有二个xib哦。如何根据不同行加载不同的xib,能否给出更明确的提示?
      

  4.   

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        if (indexPath.row==1) { //第一行
                  static NSString *simpleTableIdentifier = @"SimpleTableCell";
                    SimpleTableCell *cell = (SimpleTableCell *)[tableView               dequeueReusableCellWithIdentifier:simpleTableIdentifier];
                
            if(cell == nil) {
                     cell= [[[NSBundle mainBundle] loadNibNamed:@"SimpleTabelCell" owner:self options:nil] lastObject];;
             }
             cell.imageview_1 = [UIImage imageNamed:@"1.png"];
             cell.imageview_2 = [UIImage mageNamed:@"2.png"];
             return cell;
          }
       
        if (indexPath.row==2) {  //第二行
               static NSString *simpleTableIdentifier = @"SimpleTableCell2";
               SimpleTableCell2 *cell = (SimpleTableCell2 *)[tableView                       dequeueReusableCellWithIdentifier:simpleTableIdentifier];
                 
           if(cell == nil) {              cell= [[[NSBundle mainBundle] loadNibNamed:@"SimpleTableCell2" owner:self options:nil] lastObject];;
               }
            cell.imageview_1.image = [UIImage imageNamed:@"3.png"];
            cell.imageview_2.image = [UIImage imageNamed:@"4.png"];
            cell.imageview_3.image = [UIImage imageNamed:@"5.png"];
            return cell;
        }
        return nil;
    }
      

  5.   

    indexPath.row==0 是第一行。indexPath.row==1 是第二行  。
      

  6.   

    修改为indexPath.row=0和indexPath.row==1,程序没有崩溃,但显示的二行中,每行都只有二个图片。还是达不到第一行放二个图片,第二行放三个图片的效果。