错误:在展开Optional值时找到nil; 将数据传递给新控制器
我正在学习swift 2.我正在尝试传递被点击到新视图控制器的单元格(UITableView)的数据。 但我不断得到错误:“ unexpectedly found nil while unwrapping an Optional value
”代码行“ destination!.label.text = valueToPass
”。
以下是我的代码。
我可以知道我该怎么做才能解决它? 我花了几个小时但仍然坚持下去。
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { let indexPath = tableView.indexPathForSelectedRow; let Mycell = tableView.cellForRowAtIndexPath(indexPath!) as UITableViewCell!; valueToPass = (Mycell.textLabel?.text)! performSegueWithIdentifier("webNext", sender: self) print("\(indexPath!.row)") print(valueToPass) } override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { if (segue.identifier == "webNext") { let destination = segue.destinationViewController as? web___ViewController destination!.label.text = valueToPass } }
通过执行此操作: destination!.label.text = valueToPass
,即使在绘制或显示标签之前,您已经在标签上设置了一些文本。
而是使用一些变量将数据传递到下一个视图并在viewDidLoad
显示该数据。
let destination = segue.destinationViewController as? web___ViewController destination!.strValue = valueToPass
Web_VC:
var strValue:String? func viewDidLoad(){ super.viewDidLoad() label.text = strValue! }
- 如何在iPhone SDK中使用两个button来改变运行时的应用程序语言?
- “KashodhaniPhone”上的iOS版本与此iOS SDK的安装版本不匹配。
- 在Swift中从Parse中检索对象数据
- Xcode 6.3新文件问题
- 不是PNG filCommand copypng发出错误,但没有返回非零退出代码来指示失败
- Dans les coulisses de laconférenceDotSwift 2019
- 在iOS上为NSFileManager获得root权限(越狱)
- 从quicktime MOV文件parsingh.264 NAL单元
- iOS 8.3 – UITableView单元格不alignment,向左缩进