【发布时间】:2018-04-01 21:36:57
【问题描述】:
我有函数 didSelectRowAt indexPath,里面有一个 if 语句。
myButtonChoiceString2 成功传递了从前一个视图控制器中选择的按钮的 String title.text。
删除 if else 语句后,代码可以工作,但只能显示背部锻炼,因此包含此 if else 以显示肩部锻炼。
请你看看我在 if else 中做错了什么以获得这些警告:
- 第一个警告:变量“myCellChoice”从未发生突变;考虑更改为“让”常量
- 第二个警告:从未使用不可变值“myCellChoice”的初始化
-
第三个警告:从未使用过不可变值“myCellChoice”的初始化
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { //First Warning Below var myCellChoice = DataService.instance.backWorkouts[indexPath.row] if myButtonChoiceString2 == "BACK" { //Second Warning Below let myCellChoice = DataService.instance.backWorkouts[indexPath.row] } else if myButtonChoiceString2 == "SHOULDERS" { //Third Warning Below let myCellChoice = DataService.instance.shoulderWorkouts[indexPath.row] } videoPlayer.loadVideoID(myCellChoice.videoCode) }
【问题讨论】:
标签: ios swift if-statement