выбор строки в разделе uitableview - PullRequest
1 голос
/ 04 марта 2020

Привет, ребята, я хочу спросить, я хочу выбрать строку в разделе таблицы, когда я выбираю строку раздела, будет отображаться 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
    }

Ответы [ 3 ]

3 голосов
/ 04 марта 2020

Вы должны представить свой контроллер предупреждений в didSelect в конце

self.present(alert, animated: true)
tableView.deselectRow(at: indexPath, animated: true)
2 голосов
/ 04 марта 2020

Вы никогда не представляете предупреждение:

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) 
1 голос
/ 04 марта 2020

Вы создали экземпляр UIAlertController, но нигде не представляли его. Вы должны были представить это. Попробуй,

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)
        }))

        self.present(alert, animated: true)

        tableView.deselectRow(at: indexPath, animated: true)
    }
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...