首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法从currentTitle获得按钮UIStoryBoardSegue

无法从currentTitle获得按钮UIStoryBoardSegue
EN

Stack Overflow用户
提问于 2022-02-14 14:37:39
回答 1查看 24关注 0票数 0
代码语言:javascript
复制
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    if segue.identifier == "Choose Theme" {
        if let themeName = (sender as? UIButton)?.currentTitle {
            if let theme = themes[themeName] {
                if let cvc = segue.destination as? ConcentrationViewController {
                    cvc.theme = theme
                }
            } else {
                print("something went wrong")
            }
        } else {
            print("couldnt get current title")
        }
    }
}

这是密码。我在试着得到发件人目前的头衔。我尝试了调试,它打印“无法获得当前标题”,我得到的值是零。

我做错了什么?

提前感谢

EN

回答 1

Stack Overflow用户

发布于 2022-02-19 21:03:45

与其使用currentTitle,不如尝试使用titleLabel?.text。它似乎更可靠。我让你的程序工作(用Xcode测试)使用这个更改。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71113586

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档