我正在建立一个食谱目录,我似乎正在用这个部分撞墙。 我在解析时在类中有图像,字符串和文件。当用户选择开胃菜(表视图控制器)时,将出现一个新的视图控制器,其中包含文件中的图像,名称和配方(textview)(已经放置在解析中)。
对于我做错了什么,我们将不胜感激。
class MyAppetizerRecipes: UIViewController {
@IBOutlet var imageView: UIImageView!
@IBOutlet var name: UILabel!
@IBOutlet var myTextView: UITextView!
var recipes = [String: PFFile]()
var appetizer = [String]()
var images = [String: UIImage]()
override func viewDidLoad() {
super.viewDidLoad()
let query = PFQuery(className: "Appetizers")
query.orderByAscending("recipe")
query.findObjectsInBackgroundWithBlock { (objects, error) in
guard error == nil, let objects = objects else {
print(error)
return
}
for object in objects {
// *********** ... Appetizer Name ....... ************* //
let appetizerName = object.objectForKey("appetizer") as! String
self.name.text = self.valuePassed
// *********** ... Recipe File on Parse ....... ************* //
let recipeFile = object["recipe"] as! PFFile
recipeFile.getDataInBackgroundWithBlock({ (recipeData, error) -> Void in
if error == nil {
let data = recipeData
self.recipes[appetizerName] = PFFile(data: data!)
} else {
print(error)
}
})
// *********** ... Image ....... ************* //
let imageFile = object["imageFiles"] as!PFFile
imageFile.getDataInBackgroundWithBlock({ (imageData, error) -> Void in
if error == nil {
let data = imageData
} else {
print(error)
}
if let data = imageData {
self.images[appetizerName] = UIImage(data: data)
self.imageView.image = self.images[self.valuePassed]
}
})
}
}
}
我可以获取开胃菜的图片和名称,但无法将.txt文件从解析加载到UITextView