我正在尝试使用动物列表制作一个快速项目,然后当您点击其中一行时,您会被转移到另一个窗口,在那里它会告诉您动物的描述。
如果屏幕截图太小,以下是代码:
{
{
length: 10,
title: 'test 1',
price_total: 200.99,
},
{
length: 3,
title: 'test 2',
price_total: 3.99,
},
}
DetailViewController类代码:
import UIKit
class AnimalListTableViewController: UITableViewController
{
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 4
}
override func prepareForSegue(segue: UIStoryboardSegue,
sender: AnyObject?)
{
if let detailViewController = segue.destinationViewController as? DetailViewController, let indexPath = self.tableView.indexPathForSelectedRow {
detailViewController.Animal = animals[indexPath.row] //this is where I get the error that says "Value of type 'DetailViewController' has no member 'Animal"
}
}
}
ListOfAnimals类代码:
import UIKit
class DetailViewController: UIViewController
{
@IBOutlet weak var titleLabel: UILabel!
@IBOutlet weak var descriptionLabel: UILabel!
var animal: Animal?
var a = Animal?()
override func viewWillAppear(animated: Bool)
{
titleLabel.text = a!.name
descriptionLabel.text = a!.longDescription
}
override func viewDidLoad()
{
viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning()
{
didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
答案 0 :(得分:2)
使用:
detailViewController.animal
而不是:
detailViewController.Animal