Swift tableViewCell落后于ChildViewController

时间:2018-06-04 15:34:16

标签: ios swift uitableview uiviewcontroller childviewcontroller

我有一个奇怪的问题 -

我有一个包含两个部分的tableView - 每个部分都有一行。

在第一部分的单元格中,我添加了一个从自定义框架中检索的视图(包含大量文本字段和选择视图)。

在第二部分的单元格中,我添加了一个带有简单按钮的tableViewCell。

想法是,当用户完成第一部分中的编辑数据时,他会点击第二部分的按钮以导航到下一个视图控制器。

以下是我使用的代码 -

func numberOfSections(in tableView: UITableView) -> Int {
        return 2
    }

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

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        switch indexPath.section {
        case 0:
            cell = self.tableView.dequeueReusableCell(withIdentifier: "AddressAndTelephoneCell", for: indexPath) as! AddressAndTelephoneTableViewCell

            if let myProfile = self.myProfileViewController {
                (cell as! AddressAndTelephoneTableViewCell).contentView.addSubview(myProfile.view)
            }

        case 1:
            cell = self.tableView.dequeueReusableCell(withIdentifier: "ManageDataButtonCell", for: indexPath) as! ManageDataButtonCell

        default:
            break
        }

        return cell
    }

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

        switch indexPath.section {
        case 0:
            if let isSectionCollapsed = isCollapsed {
                if isSectionCollapsed {
                    return 360
                }
                else {
                    return 720
                }
            }
            else {
                return 360
            }

        case 1:
            if let isSectionCollapsed = isCollapsed {
                if isSectionCollapsed {
                    return 44
                }
                else {
                    return 0
                }
            }
            else {
                return 44
            }

        default:
            return 44
        }
    }

到此为止,一切都很美好。唯一的问题是我的第二部分中的按钮仅在我滚动表格视图后才显示,直到我到达该部分。

我在“查看层次结构”中查看过'第二部分中的按钮隐藏在我在第一部分中添加的视图后面。只有当我滚动到第二部分时才会出现。

我尝试使用bring(toFront: subView)layoutIfNeeded() - 以及我在StackOverflow中找到的类似解决方案,但没有任何帮助。

任何帮助 - >解决方案或替代解决方案/方法将大有帮助。

0 个答案:

没有答案