开发者社区> 问答> 正文

立即调用了dSelectItemAt indexPath,但viewController加载有延迟

当我敲击CollectionView细胞didSelectItemAt立即调用indexPath方法,但在40-50秒之后调用。myNextViewController装上子弹了。你能告诉我为什么会有这样的延迟吗?请帮我移除这个。

override func viewDidLoad() {
        super.viewDidLoad()
        startLoader()
        gatewayActionAlert.isHidden = true
        renameActionAlert.isHidden = true
        deleteActionAlert.isHidden = true
        menuOptionsView.isHidden = true

        viewInitialization()

    commandMqtt = savedData.getSavedData(key: "mqttCommand")
    responseMqtt = savedData.getSavedData(key: "mqttResponse")
    getOwnerId=savedData.getSavedData(key: "ownerId") as String

    let gatewayNameData = userDefaults.string(forKey: "gatewayName")
    if gatewayNameData != nil {
        data.append(gatewayNameData!)
    }

    getAllGatewayFromFirebase(ownerID: getOwnerId)
    getAllSharedGatewayFromFirebase(ownerID: getOwnerId)

    collectionview.dataSource=self
    collectionview.delegate=self

    NotificationCenter.default.addObserver(self, selector: #selector(reloadGateways), name: NSNotification.Name(rawValue: "reloadGatewayCollectionView"), object: nil)

    refreshCollectionview()
}

override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)
    gatewayActionAlert.isHidden = true
    renameActionAlert.isHidden = true
    deleteActionAlert.isHidden = true
    menuOptionsView.isHidden = true
    collectionview.reloadData()
}

func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
    if indexPath.section == 0 {
        if gatewaysArray.count == 0 {
            Common.showCancelAlert("Warning", message: "Please add a new Gateway to proceed", cancelTitle: "Ok", viewController: self)
        } else {
            let vc=storyboard?.instantiateViewController(withIdentifier: "AllNodeViewController")
            self.navigationController?.pushViewController(vc!, animated: true)
        }
    }    
    if indexPath.section == 1 {
        //sharedGatewaysArrayNames
        if sharedGatewaysArrayNames.count == 0 {
            Common.showCancelAlert("Warning", message: "There is no shared Gateway", cancelTitle: "Ok", viewController: self)
        } else {
            let vc=storyboard?.instantiateViewController(withIdentifier: "AllNodeViewController")
            self.navigationController?.pushViewController(vc!, animated: true)
        }
    }
}

下面是我的NextViewController方法:

override func viewDidLoad() {
        super.viewDidLoad()

        nodeActionAlert.isHidden = true
        renameActionAlert.isHidden = true
        deleteActionAlert.isHidden = true
        gatewayDetailsAlert.isHidden = true

        gatewayVersionButton.isHidden = true
        gatewayVersionButton.layer.cornerRadius = 5
        gatewayVersionButton.fadeOut()

        collectionViewNodes.dataSource=self
        collectionViewNodes.delegate=self
        mqttSession.delegate=self

        viewInitialization()
        mqttConstantsAccess()

        refreshCollectionview()
        hideKeyboardWhenTappedAround()
        if checkReachabilty() {
            self.publishData(parameters: "#BA&")
            startLoader()
            getNodeFromFirebase(ownerID: getOwnerId, gatewayID: getGatewayId)
        }
    }

    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        nodeActionAlert.isHidden = true
        renameActionAlert.isHidden = true
        deleteActionAlert.isHidden = true
        gatewayDetailsAlert.isHidden = true
    }

展开
收起
游客5akardh5cojhg 2019-12-13 15:31:50 478 0
0 条回答
写回答
取消 提交回答
问答分类:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载