gpt4 book ai didi

ios - 在uitableview部分中选择行

转载 作者:行者123 更新时间:2023-12-01 18:03:46 24 4
gpt4 key购买 nike

大家好,我想问一下我想在tableview部分中选择行,当我选择该部分行时,它将显示一个alertController。但它没有显示,我在第0部分中有另一种方法,它可以工作,但是为什么在我要选择的部分中它不起作用。你能帮助我吗?

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

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
if indexPath.section == 0 {
let selectSchoolVC = SelectSchoolPopUpVC()
selectSchoolVC.modalPresentationStyle = .fullScreen
selectSchoolVC.modalTransitionStyle = .crossDissolve
present(selectSchoolVC, animated: true, completion: nil)
} else if indexPath.section == 1 {

} else if indexPath.section == 2 {

} else if indexPath.section == 3 {

}

let alert = UIAlertController(title: nil, message: nil, preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "Log Out", style: .destructive, handler: { (_) in

ProfileServices.shared.signOutUser()

let signInVC = SigninViewController()
let navController = UINavigationController(rootViewController: signInVC)
self.present(navController, animated: true)
}))

tableView.deselectRow(at: indexPath, animated: true)
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if indexPath.section == 0 {
let cell = tableView.dequeueReusableCell(withIdentifier: "selectId", for: indexPath) as! SelectSchoolCell

return cell

} else if indexPath.section == 1 {
return UITableViewCell()
} else if indexPath.section == 2 {
let cell = tableView.dequeueReusableCell(withIdentifier: "BadgedCell", for: indexPath) as! BadgeCell
cell.accessoryType = .disclosureIndicator

let item = infoArray[indexPath.row]
cell.nameLbl.text = item["title"]
cell.badgeString = item["badge"] ?? ""
cell.badgeTextColor = .white
cell.badgeColor = .red

return cell
} else if indexPath.section == 3 {
let cell = tableView.dequeueReusableCell(withIdentifier: "helpId", for: indexPath)
let helpsArray = helpArray[indexPath.row]

cell.textLabel?.text = helpsArray
cell.textLabel?.textColor = #colorLiteral(red: 0.2, green: 0.2, blue: 0.2, alpha: 1)
cell.textLabel?.font = UIFont(name: "NunitoSans-SemiBold", size: 16)
cell.accessoryType = .disclosureIndicator
return cell
}

let cell = tableView.dequeueReusableCell(withIdentifier: "signOutId", for: indexPath)
return cell
}

最佳答案

您实际上从未显示过警报:

let alert = UIAlertController(title: nil, message: nil, preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "Log Out", style: .destructive, handler: { (_) in

ProfileServices.shared.signOutUser()

let signInVC = SigninViewController()
let navController = UINavigationController(rootViewController: signInVC)
self.present(navController, animated: true)
}))
You need to present the alert here, by doing something like:
self.present(alert, animated: true)
self.navigationController?.present(alert, animated: true, completion: nil)

关于ios - 在uitableview部分中选择行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60520628/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com