gpt4 book ai didi

ios - 如何在 if 语句中使用可选值?

转载 作者:可可西里 更新时间:2023-11-01 01:31:10 24 4
gpt4 key购买 nike

我从 xml 文件中得到“sinavid”,我想使用“id”的值(xml 中的一个标签..)

如果id=2的值,主视图转到storyboard id=2的其他 View

但我不能使用 sinavid 的值,因为可选值(我认为)

P.S:对不起我的英语:(

sinavid = haberler.objectAtIndex(indexPath.row).valueForKey("id") as! NSString as String 

if (sinavid! == "2"){

row = "b"

let viewcontroller = storyboard?.instantiateViewControllerWithIdentifier(row)
self.navigationController?.pushViewController(viewcontroller!, animated: true)


}

else {

let viewcontroller = storyboard?.instantiateViewControllerWithIdentifier(row)
self.navigationController?.pushViewController(viewcontroller!, animated: true)


}

最佳答案

if let sinaVID = sinavid, sinaVID == "2"  {
row = "b"
let viewcontroller = storyboard?.instantiateViewControllerWithIdentifier(row)
self.navigationController?.pushViewController(viewcontroller!, animated: true)
} else {
let viewcontroller = storyboard?.instantiateViewControllerWithIdentifier(row)
self.navigationController?.pushViewController(viewcontroller!, animated: true)
}

关于ios - 如何在 if 语句中使用可选值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39314916/

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