gpt4 book ai didi

iphone - 我的单元格在表格 View 中重复?

转载 作者:行者123 更新时间:2023-11-29 11:05:27 26 4
gpt4 key购买 nike

我有一个表格 View ,我在其中加载来自 2 个不同自定义类的单元格。我的代码如下所示

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier1 = @"CellIdentifier";
    static NSString *CellIdentifier2 = @"Cell";
        
    if(messagesarray==nil||[messagesarray count]==0)
    {
        
    }
   else
    {
       NSMutableDictionary *dicttable=[messagesarray objectAtIndex:indexPath.row];
        NSString *head=[dicttable objectForKey:@"gfgfg"];
        NSString *head1=[dicttable objectForKey:@"gfgfgf"];
       if([type isEqualToString:@"m"])    
        {
       if([head isEqualToString:@"NA"])
          {
             
              CustomCell *cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier1];
             if (cell == nil)
            {
            cell = [[[CustomCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier1] autorelease];
            cell.backgroundView = [ [[UIImageView alloc] initWithImage:[ [UIImage imageNamed:@"white_top_portion.png"] stretchableImageWithLeftCapWidth:0.0 topCapHeight:5.0] ]autorelease];
            }
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.nameLabel.text=head;
        cell.msg.text=head1;
        [cell.button addTarget:self action:@selector(callAction:) forControlEvents:UIControlEventTouchUpInside];     
              
              if(icon!=nil)
              {
                  if(![[ImageCache sharedImageCache] hasImageWithKey:icon])
                    {
  cell.myImageView.image = [UIImage imageNamed:@"fggtgf.png"];
                      NSArray *myArray = [NSArray arrayWithObjects:cell.myImageView,icon,@"fgfgfg.png",[NSNumber numberWithBool:NO],nil];
                      AppDelegate *appDelegate = (AppDelegate  *)[[UIApplication sharedApplication] delegate];
                      [appDelegate performSelectorInBackground:@selector(updateImageViewInBackground:) withObject:myArray];   
                    }
                  else 
                  {
                      cell.myImageView.image = [[ImageCache sharedImageCache] getImagefromCacheOrUrl:icon];
                    }
              }
              else
              {
                  cell.myImageView.image = [UIImage imageNamed:@"fgfgfg.png"];  
                  
              } 
         
        cell.label.text=sub;   
         return cell;
          }
         else
         {
            Customcellwithimage *cell = (Customcellwithimage *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier2];
             
             if (cell == nil)
             {
                 cell = [[[Customcellwithimage alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier2] autorelease];
                 cell.backgroundView = [ [[UIImageView alloc] initWithImage:[ [UIImage imageNamed:@"white_deal_bg.png"] stretchableImageWithLeftCapWidth:0.0 topCapHeight:5.0] ]autorelease];
             }
             
             cell.selectionStyle = UITableViewCellSelectionStyleNone;
             cell.datelabel1.text=subtitle;
              cell.nameLabel1.text=head;
             cell.msg1.text=head1;
             if(icon!=nil)
             {
                 if(![[ImageCache sharedImageCache] hasImageWithKey:icon])
                  {
cell.myImageView1.image = [UIImage imageNamed:@"fgfgfgf.png"];
                     NSArray *myArray = [NSArray arrayWithObjects:cell.myImageView1,icon,@"fgfgfgf.png",[NSNumber numberWithBool:NO],nil];
                     MFAppDelegate *appDelegate = (MFAppDelegate  *)[[UIApplication sharedApplication] delegate];
                     [appDelegate performSelectorInBackground:@selector(updateImageViewInBackground:) withObject:myArray];   
                     
                 }
                 else 
                 {
                     cell.myImageView1.image = [[ImageCache sharedImageCache] getImagefromCacheOrUrl:icon];
                  }
             }
             else
             {
                 cell.myImageView1.image = [UIImage imageNamed:@"fgfgfgf.png"];  
             } 
              
             cell.cellview1.image=[UIImage imageNamed:@"vf.png"];
cell.label1.text=sub;
[cell.button1 addTarget:self action:@selector(callAction:) forControlEvents:UIControlEventTouchUpInside]; 
              cell.bannerview1.image=[UIImage imageNamed:@"vfgf.png"];
              return cell;
}
        }              
    }  
}

我的问题是只有数组中的第一个元素在单元格中重复打印(单元格重复),任何人都可以帮助我知道为什么会发生这种情况。我有数组的节数,每个节只有一行。

最佳答案

如果每个部分只有一行,则每次调用此方法时 indexPath.row 都将为 0。由于行是您用来选择数组元素的行,因此它始终是同一行是合理的。

如果您要返回 [messagesarray count] 部分数和 1 行数,则需要使用 indexPath.section

关于iphone - 我的单元格在表格 View 中重复?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13840783/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com