2
我想用动物列表做一个swift项目,然后当你点击其中一行时,你会被运送到另一个窗口它告诉你动物的描述。Swift xcode错误:类型'DetailViewController'的值没有成员'Animal'
这里是代码,如果截图太小:
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.
}
}
ListOfAnimals类代码:
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
}
}
是工作,但现在我得到一个跟踪误差强调了“动物[indexPath.row]”和错误说“不能标a类型为'[ListOfAnimals]'的值' – David
如果它有效,请接受答案并创建一个新问题来描述您遇到的新问题并提供更多信息。 – RaffAl