ios - 向 UITableViewCell 添加分隔符

标签 ios objective-c uitableview

我正在构建一个应用程序(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/

相关文章:

ios - 有没有办法知道 NSURL 是指向远程服务器还是指向用户设备上的 Assets 库?

swift - TableView 的加载和平滑度

iphone - UITableView with pop 无法查看数据问题

ios - 使用Core Data保存数据时出现故障

ios - 类型 'BusinessData' 没有成员 'sortUsingComparator'

iphone - 如何使UIPickerView像UIDatePicker一样?

ios - 在方向更改时重新加载 UIPageViewController View

ios - 在另一个 View Controller 中为 AVPlayer 创建播放/暂停按钮

iphone - 使用 scrollToRowAtIndexPath 滚动到最后一个 UITableViewCell :atScrollPosition:animated using NSFetchedResultsControllerDelegate methods

ios - Flutter 应用程序无法在真实的 iOS 设备上运行(白屏)