我正在构建一个应用程序(iOS 8.0),而我已经使用 AutoLayout 和 Storyboards 构建了 UITableViewControlled。 tableView 设置为静态和分组,tableView 分隔符设置为 none。
我正在尝试使用此代码(在 viewWillAppear: 中调用)向其他两个单元格添加分隔符,但由于某种原因,它没有显示:
// Create a separator for the tableView cells
UIView *separatorViewTop = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 1.0f, self.fromCell.frame.size.width, 1.0f)];
UIView *separatorViewBottom = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 43.0f, self.fromCell.frame.size.width, 1.0f)];
separatorViewTop.backgroundColor = [UIColor grayColor];
separatorViewBottom.backgroundColor = [UIColor grayColor];
// Add it
[self.fromCell.contentView addSubview:separatorViewTop];
[self.toCell.contentView addSubview:separatorViewBottom];
fromCell 和 toCell 并在 IB 中与 IBOutlets 连接。
有人可以看一下吗? 谢谢!
最佳答案
如果您将 XIB 用于自定义单元格,那么很容易在 XIB 本身中添加这些分隔符 View 。我认为与在运行时添加相比,它更灵活。
关于ios - 向 UITableViewCell 添加分隔符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30175087/