UIViewController of lifecycle

博客围绕UIViewController的生命周期展开,虽暂无具体内容,但可知聚焦于该视图控制器在不同阶段的状态变化等信息技术相关内容。
报错override func reloadTableData() { Method does not override any method from its superclass let statsCell = TPBBaseTableCellModel.common(withStyle: .default, reuseIdentifier: "StatsCell") Cannot infer contextual base in reference to member 'default' Type 'TPBBaseTableCellModel' has no member 'common' // MARK: - UITableViewDataSource extension DeviceDashboardViewController: UITableViewDataSource { func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return sectionArray?[section].cellModelArray?.count ?? 0 } func numberOfSections(in tableView: UITableView) -> Int { return sectionArray?.count ?? 0 } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { guard let model = getCellModel(at: indexPath) else { return UITableViewCell() } let cell = super.tableView(tableView, cellForRowAt: indexPath) // 特殊处理网格视图cell if model.reuseIdentifier == "GridCell" { // 确保网格视图正确布局 deviceGridView.snp.remakeConstraints { make in make.edges.equalToSuperview().inset(16) } } return cell } }Redundant conformance of 'DeviceDashboardViewController' to protocol 'UITableViewDataSource' Overriding declaration requires an 'override' keyword Cannot use optional chaining on non-optional value of type '[TPBBaseTableCellModel]' Overriding declaration requires an 'override' keyword Cannot use optional chaining on non-optional value of type '[TPBTableSectionModel]' Cannot find 'getCellModel' in scope| 错误为以上,我给你发一个别的使用同样组件库的代码,你进行参考,要求同样写法: import UIKit let kAppToAlexaLinkReturnNotification: Notification.Name = .init(rawValue: "kAppToAlexaLinkReturnNotification") let kAppToAlexaLinkReturnNotificationIncomingURL: String = "incomingURL" class VoiceAmazonAlexaLinkViewController: SurveillanceCommonTableController { // MARK: - 属性 private var hasLinkedAlexa = false { didSet { if hasLinkedAlexa { linkAccountButton.title = LocalizedString(key: thirdPartyServicesUnlink) linkAccountButton.titleColor = .tpbRed linkAccountButton.strokeColor = .tpbRed linkAccountButton.fillColor = .clear } else { linkAccountButton.title = LocalizedString(key: thirdPartyServicesLinkAccount) linkAccountButton.titleColor = .tpbTextWhite linkAccountButton.strokeColor = .clear linkAccountButton.fillColor = .tpbPrimary } reloadData() } } private var isSnapshotOn: Bool { get { return TPSSAppContext.shared.isSnapshotOn } } private var isUpdatingLinkStatus = false private var appToAppLinkingUrl: String? private var authorizationUrl: String? private lazy var linkAccountButton: TPBButton = { let button = TPBButton.primaryButton(withTitle: LocalizedString(key: thirdPartyServicesLinkAccount)) button.strokeColor = UIColor.clear return button }() deinit { print("VoiceAmazonAlexaLinkViewController deinit") } // MARK: - View override func tpbSetupSubviews() { super.tpbSetupSubviews() setupNav() view.addSubview(linkAccountButton) tableView.alwaysBounceVertical = false } private func setupNav() { navigationItem.title = LocalizedString(key: amazonAlexa) navigationItem.leftBarButtonItem = self.tpbCreateLeftBarButtonItem(with: TPImageLiteral("common_light_back_nor"), andTarget: self, andAction: #selector(clickBack)) // 产品暂时未提供,屏蔽 // navigationItem.rightBarButtonItem = createRightBarButtonItem(with: TPImageLiteral("common_question"), andTarget: self, andAction: #selector(clickQuestionButton)) } override func tpbMakeConstraint() { super.tpbMakeConstraint() linkAccountButton.snp.makeConstraints { make in make.bottom.equalTo(view.safeAreaLayoutGuide.snp.bottom).offset(-10) make.leading.equalTo(view.safeAreaLayoutGuide.snp.leading).offset(20) make.trailing.equalTo(view.safeAreaLayoutGuide.snp.trailing).offset(-20) make.height.equalTo(44) } tableView.snp.remakeConstraints { make in make.bottom.equalTo(linkAccountButton.snp.top).offset(-10) make.top.leading.trailing.equalTo(view.safeAreaLayoutGuide) } } override func tpbBindActions() { super.tpbBindActions() linkAccountButton.addTarget(self, action: #selector(clickLinkAccountButton), for: .touchUpInside) } override func viewDidLoad() { super.viewDidLoad() loadData() } private func loadData() { hasLinkedAlexa = TPAlexaClient.shared().alexaInfo.accountLink.isLinked appToAppLinkingUrl = TPAlexaClient.shared().alexaInfo.accountLink.alexaAppUrl authorizationUrl = TPAlexaClient.shared().alexaInfo.accountLink.lwaFallbackUrl } override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) updateLinkStatus() NotificationCenter.default.addObserver(self, selector: #selector(handleAppToAlexaLinkReturn(_:)), name: kAppToAlexaLinkReturnNotification, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(updateLinkStatus), name: UIApplication.willEnterForegroundNotification, object: nil) } override func viewWillDisappear(_ animated: Bool) { super.viewWillDisappear(animated) NotificationCenter.default.removeObserver(self) ToastView.dismissLoadingToast() } // MARK: - Data Reload private func reloadData() { // 刷新cell var tempSectionArray = [TPBTableSectionModel]() // section0 let section0 = TPBTableSectionModel() var section0CellModelArray = [TPBBaseTableCellModel]() let alexaHeaderCellModel = VoiceAmazonAlexaLinkHeaderTableViewCellModel(hasLinkedAlexa: hasLinkedAlexa) section0CellModelArray.append(alexaHeaderCellModel) section0.cellModelArray = section0CellModelArray tempSectionArray.append(section0) if hasLinkedAlexa { // section1 let section1 = TPBTableSectionModel() var section1CellModelArray = [TPBBaseTableCellModel]() let snapshotCellModel = TPBBaseTableCellModel.titleSubtitle(withIcon: nil, title: LocalizedString(key: thirdPartyServicesSnapshot), subtitle: nil, value: isSnapshotOn ? LocalizedString(key: deviceSettingOn) : LocalizedString(key: deviceSettingOff), infoItemArray: nil, action: { [weak self] _, _ in let vc = VoiceAmazonAlexaSnapshotViewController() self?.navigationController?.pushViewController(vc, animated: true) }, showIndicator: true) section1CellModelArray.append(snapshotCellModel) section1.cellModelArray = section1CellModelArray tempSectionArray.append(section1) } sectionArray = tempSectionArray } // MARK: - 点击事件 @objc private func clickBack() { navigationController?.popViewController(animated: true) } @objc private func clickLinkAccountButton() { if hasLinkedAlexa { clickUnlink() return } guard let appLinkingUrl = appToAppLinkingUrl, !appLinkingUrl.isEmpty, let authUrl = authorizationUrl, !authUrl.isEmpty, let urlUniversal = URL(string: appLinkingUrl), let urlLwa = URL(string: authUrl) else { return } UIApplication.shared.open(urlUniversal, options: [.universalLinksOnly: true]) { [weak self] success in if !success { if UIApplication.shared.canOpenURL(urlLwa) { // 进入网页 UIApplication.shared.open(urlLwa, options: [:]) { [weak self] success in if success { // 防止进入前台的时候会刷新状态 self?.isUpdatingLinkStatus = true } } } else { return } } else { // 防止进入前台的时候会刷新状态 self?.isUpdatingLinkStatus = true // 已安装 return } } } @objc private func clickQuestionButton() { // TODO: zheng弹出提示h5 } // MARK: - 发送请求 @objc private func handleAppToAlexaLinkReturn(_ notification: Notification) { isUpdatingLinkStatus = false if let incomingURL = notification.userInfo?[kAppToAlexaLinkReturnNotificationIncomingURL] as? URL { let dict = getUrlParameterWithUrl(url: incomingURL) if dict.keys.contains("error") || dict.keys.contains("error_description") { updateLinkStatus() return } let authorizationModel = TPDMGetAuthorization.init(dict: dict) ToastView.showLoadingToast(cirleWithMessage: nil) let authorization = TPDAlexaAuthorization() authorization.code = authorizationModel.code authorization.state = authorizationModel.state let scope = TPAlexaClient.shared().alexaInfo.accountLink.scope authorization.scope = scope.isEmpty ? "alexa::skills:account_linking" : scope TPAlexaClient.shared().accountLinkAuthorization(authorization).addCompletion(onMainThread: { [weak self] result in ToastView.dismissLoadingToast() if result.success { // 刷新页面 self?.updateLinkStatus() } else { self?.tpbShowAlertToastFailure(withTitle: LocalizedString(key: commonFailed)) } }) } } private func getUrlParameterWithUrl(url: URL) -> Dictionary<String, String> { var parmDict: [String: String] = [:] //传入url创建url组件类 let urlComponents = URLComponents.init(string: url.absoluteString) //回调遍历所有参数,添加入字典 urlComponents?.queryItems?.forEach({ obj in parmDict[obj.name] = obj.value }) return parmDict } @objc private func updateLinkStatus() { if isUpdatingLinkStatus { return } ToastView.showLoadingToast(cirleWithMessage: nil) getAccountLinkStatus(needShowSuccess: false) } private func getAccountLinkStatus(needShowSuccess: Bool) { isUpdatingLinkStatus = true TPAlexaClient.shared().getAccountLinkStatus().addCompletion(onMainThread: { [weak self] result in self?.loadData() if result.success { if let hasLinkedAlexa = self?.hasLinkedAlexa, hasLinkedAlexa { // 只有连接了才有请求Snapshot的必要 self?.getSnapshot() } else { ToastView.dismissLoadingToast() if needShowSuccess { self?.tpbShowAlertToastSuccess(withTitle: LocalizedString(key: commonSuccess)) } self?.isUpdatingLinkStatus = false } } else { ToastView.dismissLoadingToast() self?.isUpdatingLinkStatus = false } }) } private func getSnapshot() { RequestAsyncHandler.default.perform({ () -> TPSSCode in return TPSSAppContext.shared.getCurSnapshot() }) { [weak self] result in ToastView.dismissLoadingToast() self?.reloadData() self?.isUpdatingLinkStatus = false } } private func clickUnlink() { tpbShowAlert(withTitle: LocalizedString(key: thirdPartyServicesUnlinkAlertTitle), messsage: nil, cancelText: LocalizedString(key: commonCancel), cancelCallback: nil, deleteText: LocalizedString(key: thirdPartyServicesUnlink)) { [weak self] in self?.unlink() } } private func unlink() { ToastView.showLoadingToast(cirleWithMessage: nil) TPAlexaClient.shared().unlinkAuthorization().addCompletion(onMainThread: { [weak self] result in if result.success { self?.getAccountLinkStatus(needShowSuccess: true) } else { ToastView.dismissLoadingToast() self?.tpbShowAlertToastFailure(withTitle: LocalizedString(key: commonFailed)) } }) } }
12-03
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

hiwb

您的鼓励是我创作最大的动力!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值