首页 > 解决方案 > willDisplay 单元格中的函数也在视图加载时调用

问题描述

override func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {

        if userType == "2" {
        if (indexPath.section == (page * 10) - 2) && (page > 0) && (pagedone == false){
           self.setupInbox(self.appDele!.glat, slng: self.appDele!.glong, animate: false)
            if (page >= 1 ) {
                page = page + 1
            }
        }
        } else if userType == "1" {
            if indexPath.section == 10 {
            showAlert()
            }
        }
    }



override func numberOfSections(in tableView: UITableView) -> Int {
        return arrayOfRels.count
    }

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

override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        guard let release = arrayOfRels[exist: indexPath.section] else { return 0 }

        if release.isAttendingNow == "1" {
            return 120.0
        }

        return 90.0

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

    override func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        return 5
    }

    // Make the background color show through
    override func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
        let headerView = UIView()
        headerView.backgroundColor = UIColor.clear
        return headerView
    }

加载视图时也会调用 showAlert() 函数。

仅应在 indexPath.section == 10 时调用

我怎样才能让它工作?

标签: iosswiftuitableview

解决方案


如果您的屏幕足够大,可以在之后立即显示第 10 节viewDidLoad,那么showAlter()viewDidLoad假设您userType1


推荐阅读