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

时间:2017-05-21 17:18:17

标签: 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
}

1 个答案:

答案 0 :(得分:0)

我相信设置:

cell.selectionStyle = .none

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