我正在使用苹果的Swift iOS教程,出现了一个错误:
无法使用'UIImagePickerController.InfoKey'类型的索引来访问'[String : Any]'类型的值。
他们定义的函数如下。
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
// The info dictionary may contain multiple representations of the image. You want to use the original.
guard let selectedImage = info[UIImagePickerControllerOriginalImage] as? UIImage else {
fatalError("Expected a dictionary containing an image, but was provided the following: \(info)")
}
// Set photoImageView to display the selected image.
photoImageView.image = selectedImage
// Dismiss the picker.
dismiss(animated: true, completion: nil)
}
我正在使用 Xcode 版本 10.0 beta 3,其中包含 Swift 4.2。
我想了解如何遍历文档以了解可能发生了什么更改或故障。
button.addTarget(self, action: #selector(RatingControl.ratingButtonTapped(button:)), for: .touchUpInside)
。如果其他人遇到同样的问题 - 我通过在类行的开头添加@objcMembers
来解决它,就像这样:@objcMembers class RatingControl: UIStackView {
。请参见https://www.hackingwithswift.com/example-code/language/how-to-fix-argument-of-selector-refers-to-instance-method-that-is-not-exposed-to-objective-c。 - Keara