第一行和第二行之间缺少 swift tableview 分隔线

标签 swift tableview cell

我创建了一个表格,第一个和第二个单元格之间的分隔线似乎丢失了,其余的都在那里。如果我滚动到顶部并返回,则会出现该行: enter image description here

下面是 TableView 行函数。我从 mysql 数据库读取并显示行。

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int
{
    return dbarray_id.count
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
{
    //for(var i = 0; i < dbarray_id.count; i += 1)
    //for i in 0..<dbarray_code.count
    //{
    //    //newVars.put_timelog("cellForRowAtIndexPath_uiswitch :\(uiswitch_onoff[i])  \(uiswitch_enabled[i])")
    //}

    let cell = tableView.dequeueReusableCell(withIdentifier: "pushgroups_tvc") as! pushgroups_tvc

    cell.backgroundColor = UIColor.clear

    cell.txtsubject.text = dbarray_title[(indexPath as NSIndexPath).row]
    cell.txtbody.text = dbarray_description[(indexPath as NSIndexPath).row] 

    cell.txtsubject.numberOfLines=0
    cell.txtsubject.lineBreakMode = NSLineBreakMode.byWordWrapping

    cell.txtbody.numberOfLines=0
    cell.txtbody.lineBreakMode = NSLineBreakMode.byWordWrapping

    cell.txtsubject.textColor = UIColor.blue
    cell.txtsubject.font = newVars.font_subject
    cell.txtbody.font = newVars.font_body

    cell.addgroup.tag = (indexPath as NSIndexPath).row
    //update switch to selected value
    //cell.addgroup.on = false
    cell.addgroup.isOn = uiswitch_onoff[(indexPath as NSIndexPath).row]
    if uiswitch_enabled[(indexPath as NSIndexPath).row] == true
    {
        cell.addgroup.isEnabled = true
        cell.addgroup.backgroundColor = UIColor.clear
    }
    else
    {
        cell.addgroup.isEnabled = false
        cell.addgroup.backgroundColor = UIColor.clear
    }

    cell.txtaccesscode.text = ""
    cell.txtaccesscode.isEnabled = true

    cell.txtaccesscode.tag = (indexPath as NSIndexPath).row
    cell.txtaccesscode.tintColor = UIColor.blue
    cell.txtaccesscode.autocapitalizationType = .allCharacters


    //GGGGGG
    cell.txtaccesscode.addTarget(self, action: #selector(textFieldTyping_access), for: .editingChanged)

    if dbarray_public[(indexPath as NSIndexPath).row] == "Y"
    {
         //cell.backgroundColor =  UIColor.blueColor().colorWithAlphaComponent(0.2)
         cell.txtaccesscode.text = ""
         cell.txtaccesscode.isEnabled = false
         cell.addgroup.isEnabled = true
         cell.txtaccesscode.isHidden = true
    }
    if dbarray_public[(indexPath as NSIndexPath).row] == "R"
    {
        cell.txtaccesscode.isHidden = false
        //cell.backgroundColor =  UIColor.redColor().colorWithAlphaComponent(0.2)
    }
    if dbarray_public[(indexPath as NSIndexPath).row] == "H"
    {
        //cell.backgroundColor =  UIColor.greenColor().colorWithAlphaComponent(0.2)
    }

    cell.selectionStyle = .none
    cell.layoutMargins = UIEdgeInsets.zero
    cell.separatorInset = UIEdgeInsets.zero
    cell.layoutMargins = UIEdgeInsets.zero

     cell.backgroundColor = newVars.hexStringToUIColor(hex: newVars.tableview1_background_color).withAlphaComponent(CGFloat(newVars.tableview1_background_color_alpha))

    return cell
}


func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath)
{
    newVars.put_timelog(timedata: "GORDON pushgroups_vc_textFieldDidBeginEditing(textField ")

    //tableView.separatorStyle = UITableViewCellSeparatorStyle.singleLineEtched
    tableView.separatorStyle = UITableViewCellSeparatorStyle.singleLine
    tableView.separatorColor = UIColor.black
    //tableView.backgroundColor = UIColor.red //overrides cell color
    tableView.showsHorizontalScrollIndicator = false
    tableView.showsVerticalScrollIndicator = false
}

最佳答案

我相信设置:

cell.selectionStyle = .none

然后以编程方式选择一个单元格,就像在 viewDidLoad 方法中一样会导致此错误。 我有同样的问题并使用附件复选标记和禁用选择解决了它。在我删除默认选择第一个单元格的代码后,错误消失了。

关于第一行和第二行之间缺少 swift tableview 分隔线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44099683/

相关文章:

Swift MVVM - 使用协议(protocol)来处理 viewModel 事件

ios - 扩展 UnicodeScalar : Creating an init method from a Character

ios - 滑动以查看 UITableViewCells 崩溃时的操作

html - 使用 div : middle vertically aligned text, 和一个单元格中的内容来模拟表格单元格的行为,从而扩大两个单元格的高度

css - 更改 TableView 中单个数据单元格的颜色

ios - TableView 静态单元格 : how to add constraint to bottom to the cell

swift - 如果使用 CoreData,是否需要缓存

arrays - 随机选择一个类的实例化并显示?

json - 使用使用 SwiftyJSON 的函数填充 Tableview

swift - 如何使用 eureka lib 在 View 中调整表单 View Controller ?