iOS/Swift新产品。我正在尝试将一个项目(它只是通过NSData init()方法从URL获取内容)从Swift 2迁移到Swift 3,并且遇到了以下几个问题:
prepareForSegue在一个ViewController。segue本身工作正常,但是我无法从原始控制器中从UILabel中提取文本并将其发送到目标控制器。由于某些原因,目标VC UIlabel仍然显示默认值。Segue代码:
如果让标识符= segue.identifier{ if标识符== "showUserDetailSegue"{ if detailsViewController = segue.destination as?DetailsViewController,让单元格=发送者作为?UserInfoTableViewCell,让text = cell.textLabel?.text{ detailsViewController.text = text }}detailsViewController.text是一个使用didSet属性的公共变量。
DestinationVC代码:
var text: String?{
didSet{
updateUI()
}
}
private func updateUI(){
self.detailsTextView.text = text
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBOutlet weak var detailsTextView: UILabel!2.我的一个GET请求URL之间有一些空格。例如,如果我们接受一个示例URL (如:http://www.omdbapi.com/?t=Game%20of%20Thrones&Season=1 ),那么异步调用就会失败,出现一个"URL无效“。我们应该对此进行某种编码吗?
任何提示,提示都是非常感谢的。
谢谢。
发布于 2016-12-28 18:57:25
您的UILabel在DetailsViewController中是可选的未包装的吗?很有可能在那个时候它仍然是nil。应该配置视图的最早时刻是在viewDidLoad中。
只需删除didSet处理程序并将UILabel的文本设置为viewDidLoad中的self.text。
https://stackoverflow.com/questions/41368018
复制相似问题