【问题标题】:Remove UITableView separator line删除 UITableView 分隔线
【发布时间】:2017-03-12 22:52:43
【问题描述】:

我想删除 2 个视图之间的界线。分隔 2 UITableViewCells 的行:

我声明表格视图如下:

self.tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
self.tableView.delegate = self;
self.tableView.dataSource = self;
self.tableView.keyboardDismissMode = UIScrollViewKeyboardDismissModeOnDrag;
self.tableView.scrollEnabled = NO;
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
self.tableView.estimatedRowHeight = 85.0;
self.tableView.rowHeight = UITableViewAutomaticDimension;

所以我实际上写了 - self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;

为什么它仍然存在?

【问题讨论】:

  • 试试这个:cell.separatorInset = UIEdgeInsetsMake(0.f, cell.bounds.size.width, 0.f, 0.f); in cellForRow 方法
  • 你也可以在viewWillLayoutSubViewviewController self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;的方法上使用这一行

标签: ios objective-c uitableview


【解决方案1】:

目标-C:

[self.tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];

斯威夫特:

self.tableView.separatorStyle = UITableViewCellSeparatorStyle.None

Swift 5.0 将其重命名为:

self.tableView.separatorStyle = UITableViewCell.SeparatorStyle.none

在 viewDidLoad() 方法中应用该行。

如果你想从 nib 文件中进行操作,请将 tableView 的 Separator 属性设置为 None

【讨论】:

  • 谢谢,这是故事板中的问题,我已经在 .m 文件中设置了。
  • 设置separatorStyle 似乎没有效果,除非表格视图位于窗口的视图层次结构中。如果你有一些UIView 子类的表格视图,你可以在didMoveToWindow 方法中设置它。
【解决方案2】:

对于 Swift 4:

tableView.separatorStyle = .none

【讨论】:

    【解决方案3】:

    对于 Swift 5

     viewDidLoad(){
         tableView.separatorStyle = UITableViewCell.SeparatorStyle.none
        }
    

    对于Objective-C

    [self.tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
    

    或者你可以使用界面生成器来代替


    更多信息

    SeparatorStyle

    【讨论】:

    • 感谢您推荐界面生成器。我不知道
    【解决方案4】:

    使用 UI 隐藏 tableView 分隔符

    在这里您选择 TableView 的“分隔符”属性为“无”。

    https://i.stack.imgur.com/8KyH5.png

    【讨论】:

      【解决方案5】:

      您可以使用以下代码,因为它不会删除部分的行分隔符。:

      -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
      {
      
          // Your code here //
      
          cell.separatorInset = UIEdgeInsetsMake(0.f, [UIScreen mainScreen].bounds.size.width, 0.f, 0.f);
      
      }
      

      【讨论】:

        【解决方案6】:

        在 Swift 4.2 中,您可以方便地在 tableViewseparatorStyle 上使用点符号。像这样:

        tableView.separatorStyle = .none

        【讨论】:

          【解决方案7】:

          我的问题是当我添加 tableView 槽代码时,我有单独的 func 来显示 tableview 并将它添加到 mainView(从底部滑动)我需要添加这个 tableView.separatorStyle = .none 在那个函数中,在 mainView 上添加 tableView 并对其进行约束。

          【讨论】:

            【解决方案8】:

            正如@gonsee 指出的那样: “设置 separatorStyle 似乎没有效果,除非表格视图位于窗口的视图层次结构中。如果您在某些 UIView 子类上有一个表格视图”

            如果你的表在 UIView 中,你应该在 viewDidAppear 中设置分隔符样式。

            override func viewDidAppear(_ animated: Bool) {
                    self.contentView.documentTableView.separatorStyle = .none
            }
            

            【讨论】:

              【解决方案9】:

              你可以用不同的方式归档这些东西

              1. 你也可以使用viewDidLoad()中的这一行代码

                override func viewDidLoad() {
                   super.viewDidLoad()
                   tableView.tableFooterView = UIView()
                }
                

              1. 你可以在故事板上做


              1. viewDidLoad()中设置代码

                override func viewDidLoad() {
                   super.viewDidLoad()
                   tableView.separatorStyle = .none
                }
                

              【讨论】:

                【解决方案10】:

                添加这一行

                tableView.separatorStyle = .none
                

                【讨论】:

                  【解决方案11】:

                  viewDidLoad 中添加 tableView.separatorStyle = .none

                  例子:

                  override func viewDidLoad() {
                      super.viewDidLoad()
                      ...
                      self.tableView.separatorStyle = .none // <---
                      ...
                  }
                  

                  【讨论】:

                    猜你喜欢
                    • 2015-05-14
                    • 2010-10-29
                    • 2011-06-15
                    • 2021-10-21
                    • 2012-01-11
                    • 1970-01-01
                    • 2011-02-05
                    • 1970-01-01
                    相关资源
                    最近更新 更多