最佳答案
我正在用 Swift 编写我的第一个 iOS 应用程序(仅限 iPhone)。主应用程序视图应该允许用户从照片库中选择图像。
我发现了以下 ViewController Swift的示例代码:
class ViewController: UIImagePickerController, UINavigationControllerDelegate, UIImagePickerControllerDelegate {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func tableView(tableView: UITableView!, didSelectRowAtIndexPath indexPath: NSIndexPath!) {
var imagePickerController = UIImagePickerController()
imagePickerController.delegate = self
imagePickerController.sourceType = UIImagePickerControllerSourceType.SavedPhotosAlbum
imagePickerController.allowsEditing = true
self.presentViewController(imagePickerController, animated: true, completion: { imageP in
})
}
func imagePickerController(picker: UIImagePickerController!, didFinishPickingImage image: UIImage!, editingInfo: NSDictionary!) {
let selectedImage : UIImage = image
println(selectedImage)
}
}
并有以下视图控制器场景-
View Controller
- Top Layout Guide
- Bottom Layout Guide
- View
- Image View
First Responder
Exit
但是,当我启动应用程序时,只显示黑屏。我做错了什么? 我发现的另一个 示例代码是在 Objective-C 中,这对我没有帮助。