【问题标题】:Help me Checkbox's check mark is hidden帮帮我 复选框的复选标记被隐藏
【发布时间】:2011-07-14 19:05:15
【问题描述】:

请看我下面的代码sn-p。我将复选框放入我的单元格中,我可以选中或取消选中该复选框。但是当我滚动表格视图时,复选框的复选标记被隐藏了。
我的意思是我通过设置图像来设置复选标记。

请任何人帮我解决这个问题。

感谢您的宝贵时间。

// Customize the appearance of table view cells.
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {

      static NSString *CellIdentifier = @"Cell";

      UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

      if (cell == nil)
      {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"en"] autorelease];

      cb = [[UIButton alloc] initWithFrame:CGRectMake(5,10, unselectedImage.size.width, unselectedImage.size.height)];

    [cb setImage:unselectedImage forState:UIControlStateNormal];
    [cb setImage:selectedImage forState:UIControlStateSelected];
    [cb addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchDown];
    [cell.contentView addSubview:cb];

    }

    if ( tableView == myTableView )
    {
      titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(60, 0, 150, 35)];
      titleLabel.font = [UIFont boldSystemFontOfSize:13];
      titleLabel.textColor = [UIColor blackColor];  
      [cell.contentView addSubview:titleLabel];

      cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; 
    }

      return cell;
    }

【问题讨论】:

    标签: iphone uitableview iphone-sdk-3.0


    【解决方案1】:

    DidSelectRowAtindexPath:

    if ([set containsObject:indexPath]) 
    {
        [set removeObject:indexPath];
    }
    else 
    {
        [set addObject:indexPath];
    }
    

    CellForRpwAtIndexPath:

    if ([set containsObject:indexPath]) 
    {
        cell.imgView.image=[UIImage imageNamed:@"chealBox1.png"];
    }
    else 
    {
        cell.imgView.image=[UIImage imageNamed:@"chealBox2.png"];
    }
    

    这里设置为NSMutableSet,您必须在 viewDidLoad 中创建属性、合成和分配......肯定会工作......

    【讨论】:

      【解决方案2】:

      取自here

      如果我正确理解 TableView 概念,您需要将复选标记设置保存在其他位置。如果您的单元格被滚动出视图,TableViewController 可能会释放该单元格。然后,当要求您在委托中重新创建单元格时,您必须将其恢复为与以前相同的状态。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-08-09
        • 1970-01-01
        • 1970-01-01
        • 2011-03-13
        • 2013-08-10
        • 1970-01-01
        相关资源
        最近更新 更多