您好我曾尝试在线关注教程,但似乎无法使其正常运行。
我正在尝试使用来自表格视图的按下单元格中的信息填充视图控制器...它选择了已选择的单元格,但随后打开视图控制器两次...它也不会填充ui标签
请告知谢谢。
用户选择单元格的表格视图类;
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let indexPath = tableView.indexPathForSelectedRow!
let currentCell = tableView.cellForRow(at: indexPath)! as UITableViewCell
title = currentCell.textLabel?.text
performSegue(withIdentifier: "passInfoSegue", sender: self)
}
func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?){
if (segue.identifier == "passInfoSegue") {
// initialize new view controller and cast it as your view controller
let viewController = segue.destination as! NextViewController
// your new view controller should have property that will store passed value
viewController.passedValue = title!
}
}
下一个视图控制器;
class NextViewController : UIViewController{
var passedValue : String!
@IBOutlet weak var featLabel: UITextView!
@IBOutlet weak var descripLabel: UITextView!
@IBOutlet weak var titleLabel: UILabel!
@IBOutlet weak var ampImage: UIImageView!
override func viewDidLoad() {
super.viewDidLoad()
featLabel.text = passedValue
}
}