1

我正在使用一个UITableView和一个自定义单元格checkbox。我有超过 1 个部分。当在第一部分中检查一个复选框时,例如,ROW = 0和部分= 0的单元格时,我保存数据并起作用。但也检查了 row = 0 和 section = 1 中的单元格!我怎样才能使这些部分之间有所不同?

太感谢了!

4

2 回答 2

3

以下示例代码将帮助您解决您的情况。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *CellIdentifier = @"Cell";

    CustomCell *cell = (CustomCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
       cell = (CustomCell *) [[[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner:self options:nil] objectAtIndex:0];
       cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    cell.checkBox = [self fillCheckBoxStatus:indexPath];//This method will say about check box whether going to SET or NOTSET. 
    //...
    return cell;
}
于 2013-04-19T11:59:19.940 回答
-2

习惯dequeueReusableCellWithIdentifier喜欢nil下面...

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:nil];
    if (cell == nil) {

    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:nil] autorelease];
      ////you another code..
   }
  return cell;
}
于 2013-04-19T11:57:44.013 回答