2017-05-21 76 views
0

我创建了一个表格,看起来第一个和第二个单元格之间的分隔线缺失,剩下的就在那里。如果我滚动到顶部和背面的线出现: enter image description here第一行和第二行之间缺少swift tableview分隔线

下面是tableview rows的函数。我从一个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 
} 
+0

是模拟器还是真实设备的屏幕截图? – ocanal

+0

检查真实设备,在模拟器上它看起来像但在设备上它将工作 –

+0

我检查了两者模拟器和iPad和相同,第一和第二之间没有线 –

回答

0

我认为设置:

cell.selectionStyle = .none 

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

相关问题