【问题标题】:ios - view position inside cell tableview changes only after scrollingios - 单元格表格视图内的视图位置仅在滚动后才会更改
【发布时间】:2015-08-02 19:13:35
【问题描述】:

我有一个使用 ios 8.0+ 的表格,我在每个单元格中添加了一个复选框 - 在 iphone 5 上效果很好,但是在 iphone 6 上进行测试时 - 复选框只有在滚动后才处于正确的位置...... (第二张是滚动后的)

**** 还不能添加照片:) 所以我在第一次加载时实际看到的是复选框得到了一些右填充 -> 在我滚动一些复选框后向右移动 - 它们应该在哪里 下面的代码 谢谢!

CGFloat y =self.navigationController.navigationBar.frame.size.height + self.navigationController.navigationBar.frame.origin.y;
tableData = [[UITableView alloc] initWithFrame:CGRectMake(5, y+10, self.view.frame.size.width, self.view.frame.size.height - y -30 - nextButton.frame.size.height -10) style:UITableViewStylePlain];
tableData.dataSource = self;
tableData.delegate = self;



[self.view addSubview:tableData];

- (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:CellIdentifier];

  }
   else
    {
        CTCheckbox *check =  [cell.subviews objectAtIndex:1];
        [check removeFromSuperview];
    }






CTCheckbox *checkbox;

cell.contentView.backgroundColor = [UIColor grayColor];
checkbox = [[CTCheckbox alloc] initWithFrame:CGRectMake(cell.frame.size.width-60, cell.frame.size.height/2-10, 50, 20.0)];
checkbox.alpha = 0.7;
[checkbox addTarget:self action:@selector(checkboxDidChange:) forControlEvents:UIControlEventValueChanged];
checkbox.tag = indexPath.row;
[checkbox setColor:[BlendedColors pink] forControlState:UIControlStateNormal];

//Expertise label
UIFont *myFont = [UIFont systemFontOfSize:12.0 ];
cell.textLabel.font  = myFont;

cell.textLabel.text = [experties objectAtIndex:indexPath.row];
cell.textLabel.textColor = [BlendedColors black];
[cell addSubview:checkbox];
cell.selectionStyle = UITableViewCellStyleDefault;


if([[selectedCheckBox objectAtIndex:indexPath.row]isEqualToString:@"YES"])
{
    checkbox.checked = YES;
}
else{
    checkbox.checked = NO;
}


//cell.contentView.backgroundColor = [UIColor blackColor];
return cell;

}

【问题讨论】:

    标签: ios uitableview tableview cell


    【解决方案1】:

    固定 - 第一个单元格宽度始终为 320

    添加了 3 行

    if (cell == nil) {
    
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
        //Fix Bug - first cell view is always 320 - now its dynamic(cell width = device width)
            CGRect cellFrame = cell.frame;
            cellFrame.size.width = self.view.frame.size.width;
            cell.frame = cellFrame;
    
    
      }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-03-19
      • 1970-01-01
      • 2011-04-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-12-13
      • 1970-01-01
      相关资源
      最近更新 更多