我有一个使用ios 8.0+的tablewiew,我在每个单元格中添加了一个复选框 - 在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;
}
答案 0 :(得分:0)
固定 - 第一个单元格宽度始终为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;
}