Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/99.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 重新加载表视图后,最后一个静态单元格分隔符行出现_Ios_Objective C_Swift_Uitableview - Fatal编程技术网

Ios 重新加载表视图后,最后一个静态单元格分隔符行出现

Ios 重新加载表视图后,最后一个静态单元格分隔符行出现,ios,objective-c,swift,uitableview,Ios,Objective C,Swift,Uitableview,我正在使用下面的代码来摆脱最后一个静态单元格底部分隔符行,它非常适用于不需要重新加载tableView的情况。重新加载后,将显示tableView分隔线 仅超级VC中的代码: override func viewDidLoad() { super.viewDidLoad() let footerFrame = CGRect(x: 0.0, y: 0.0, width: tableView.frame.size.width, height: 1.0) tableV

我正在使用下面的代码来摆脱最后一个静态单元格底部分隔符行,它非常适用于不需要重新加载tableView的情况。重新加载后,将显示tableView分隔线

仅超级VC中的代码:

override func viewDidLoad() {
    super.viewDidLoad()
    let footerFrame = CGRect(x: 0.0, y: 0.0, width: 
    tableView.frame.size.width, height: 1.0)
    tableView.tableFooterView = UIView(frame: footerFrame)
}
致电后:

fileprivate func showDatePicker()
{
    datePicker.setValue(UIColor.white, forKey: "textColor")
    showsDatePicker = true

    tableView.beginUpdates()
    tableView.endUpdates()

    tableView.contentInset = UIEdgeInsets(top: -20.0, left: 0.0, 
    bottom: 0.0, right: 0.0)
}
在我孩子的tableView(didSelectRowAt indexPath:_)中,我只是在以下位置使用日期选择器更改单元格的高度:

func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {

    guard showsDatePicker else {
       switch indexPath.row {
        case CellIndex.withDatePicker:
            return 0.0
        default:
            return 44.0 
        }
    }

    switch indexPath.row {
        case CellIndex.withDatePicker:
            return 217.0
        default:
            return 44.0 
        }
}

然后我画了分隔线!可能是因为静态单元格的使用,唯一的方法是在故事板中的每个viewController中添加空白视图?将
tableView.tableFooterView=UIView()
替换为
viewDid/WillLayoutSubviews
会导致空屏效果。我不想在故事板中为我的所有控制器添加一个空白视图,也许有一种方法可以通过编程实现

在显示最后一个单元格之前

if indexPath.row == Your_last_Cell {

  cell.separatorInset = UIEdgeInsetsMake(0, cell.bounds.size.width, 0, 0);

}
创建具有最小高度的页脚:

func tableView(_ tableView: UITableView, 
heightForFooterInSection section: Int) -> CGFloat{

// This will create a "invisible" footer
     return 0.01f; //CGFLOAT_MIN
}


我实现这一结果的方法如下:

在viewDidLoad函数中

override func viewDidLoad() {
    super.viewDidLoad()
    // Add this line
    yourTableView.tableFooterView = UIView()
}
定义表格视图的节数

func numberOfSectionsInTableView(tableView: UITableView) -> Int {
    return 2
}
在cellForRowAtIndexPath函数中

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var cell: UITableViewCell?
switch indexPath.section {
    case 0:
        cell = tableView.dequeueReusableCellWithIdentifier("yourfirstcell")
        if indexPath.row == yourLastRowIndex {
        self.separatorInset = UIEdgeInsetsMake(0, self.bounds.size.width, 0, 0)
    }
    case 1:
        cell = tableView.dequeueReusableCellWithIdentifier("yoursecondcell")
    default:
        break
    }
    return cell!
}

这种方法将对您有所帮助。

您能分享代码吗,您到目前为止做了什么?是的,当然,但没有太多内容来共享我的带有静态单元格的tableView的超级类中的func viewDidLoad(){super.viewDidLoad()tableView.tableFooterView=UIView()},在我重新加载TableView之前,它会删除分隔符。我建议您在问题中共享上述代码(编辑您的问题),并请共享TableView委托和数据源方法。我已尽了最大努力,希望现在更好,非常感谢!谢谢,但我想找到更通用的方法,如果有更新的答案,如果您正在寻找更通用的方法,您只需隐藏
tableview
默认分隔符
tableview.separatorStyle=UITableViewCellSeparatorStyle.none
并创建您自己的自定义分隔符。输出相同,它隐藏分隔符,直到我重新加载添加最后2个委托方法。丑陋的解决方案是将分隔符设置为.none,然后手动为每个单元格添加一个视图,因此您的答案是我认为最接近的一个。谢谢,但我使用的是静态单元格,根本不想实现
cellforrowatinexpath
,如果我真的实现了它,我应该为其他单元格返回什么?只是
UITableViewCell()
不行,我想…@DmitriyIvashin根据您的场景更新了答案。
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var cell: UITableViewCell?
switch indexPath.section {
    case 0:
        cell = tableView.dequeueReusableCellWithIdentifier("yourfirstcell")
        if indexPath.row == yourLastRowIndex {
        self.separatorInset = UIEdgeInsetsMake(0, self.bounds.size.width, 0, 0)
    }
    case 1:
        cell = tableView.dequeueReusableCellWithIdentifier("yoursecondcell")
    default:
        break
    }
    return cell!
}