Ios Swift xcode错误:类型为';DetailViewController';没有成员';动物';
我试图制作一个包含动物列表的swift项目,然后当你点击其中一行时,你会被传送到另一个窗口,在那里它会告诉你动物的描述 以下是屏幕截图太小时的代码:Ios Swift xcode错误:类型为';DetailViewController';没有成员';动物';,ios,swift,xcode,uitableview,Ios,Swift,Xcode,Uitableview,我试图制作一个包含动物列表的swift项目,然后当你点击其中一行时,你会被传送到另一个窗口,在那里它会告诉你动物的描述 以下是屏幕截图太小时的代码: import UIKit class AnimalListTableViewController: UITableViewController { override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
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"
}
}
}
DetailViewController类的代码:
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.
}
}
动物类代码列表:
import Foundation
let animals = [
ListOfAnimals(name: "Cow",
shortDescription: "Cattle",
longDescription: "A cow is a mature female and bull of an adult male of a bovine family. A heifer is a female cow that hasn't had a calf yet. Cattle is the name for the whole cow family. THere are about 920 different breeds of cows in the world."),
ListOfAnimals(name: "Bird",
shortDescription: "Usually small, has wings, feathers, and can fly.",
longDescription: "A warm-blooded egg-laying vertebrate distinguished by the possession of feathers, wings, and a beak and (typically) by being able to fly."),
ListOfAnimals(name: "Dolphin",
shortDescription: "A large fish",
longDescription: "A small gregarious toothed whale that typically has a beaklike snout and a curved fin on the back. Dolphins have become well known for their sociable nature and high intelligence."),
ListOfAnimals(name: "Dog",
shortDescription: "Man's best friend",
longDescription: "A domesticated carnivorous mammal that typically has a long snout, an acute sense of smell, and a barking, howling, or whining voice. It is widely kept as a pet or for work or field sports."),
ListOfAnimals(name: "Zebra",
shortDescription: "A horse with white and black stripes",
longDescription: "an African wild horse with black-and-white stripes and an erect mane."),
]
class ListOfAnimals
{
var name: String
//var type: Type
var shortDescription: String
var longDescription: String
init(name: String, shortDescription: String, longDescription: String)
{
self.name = name
self.shortDescription = shortDescription
self.longDescription = longDescription
}
}
使用:
而不是:
detailViewController.Animal
这是可行的,但现在我得到了一个后续错误,在“animals[indexath.row]”下面加了下划线,错误是“不能为“[ListoFaimals]”类型的值下标。如果可行,请接受答案并创建一个新问题,描述您遇到的新问题,并提供更多信息。
detailViewController.Animal