我正在将一个 uitableview 单元格作为子视图添加到 UIView 中,这也是 ViewController 视图的子视图。但由于某种原因,当我将 UITableViewCell 初始化为更小的东西时,它仍会在屏幕上拉伸 320 像素。
即使我将视图的子视图缩小,它仍然保持 320 像素宽。我想知道它是否是层次结构问题?我觉得我的代码是正确的,但也许我只是遗漏了一些小东西......
//..
// This UIView holds both custom UITableViewCell and UIButton and is placed at the top of the current UIView
cellContainer = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, 200.0, 44.0)];
cellContainer.backgroundColor = [UIColor greenColor];
// Select all UITableViewCell
selectAllCell = [[UITableViewCell alloc] initWithFrame:CGRectMake(0.0, 0.0, 100.0, 7.0)];
selectAllCell.textLabel.text = @"Select all"; // Set text
// selectAllCell.accessoryType = UITableViewCellAccessoryCheckmark;
selectAllCell.backgroundColor = [UIColor redColor]; // set bg color
// Create non visible UIButton that sits over customTableviwecell wich allows you to set a selctor on the button press
UIButton *selectAllButton = [[UIButton alloc] initWithFrame:CGRectMake(0.0, 0.0, 200.0, 50.0)];
[selectAllButton addTarget:self action:@selector(selectAll:) forControlEvents:UIControlEventTouchUpInside];
// Add custom Cell and UIButton to cellContainer view
[cellContainer addSubview:selectAllCell];
[cellContainer insertSubview:selectAllButton aboveSubview:selectAllCell];
// Ass cellContainer to self.view
[self.view insertSubview:cellContainer atIndex:1];
//..