我在尝试调试malloc错误/内存泄漏时遇到问题。下面是我的代码:
class UploadPostController: UITableViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate, TOCropViewControllerDelegate {
var myPickerController : UIImagePickerController?
override func viewDidLoad() {
super.viewDidLoad()
}
override func viewWillLayoutSubviews() {
setupNavBarButtons()
}
func setupNavBarButtons() {
let uploadBarButtonItem = UIBarButtonItem(title: "Upload", style: .plain, target: self, action: #selector(displayImagePickerButtonTapped))
navigationItem.rightBarButtonItem = uploadBarButtonItem
}
func displayImagePickerButtonTapped() {
myPickerController = UIImagePickerController()
myPickerController?.delegate = self
myPickerController?.sourceType = UIImagePickerControllerSourceType.photoLibrary
self.present(myPickerController!, animated: true, completion: nil) // crashes here.
}
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
if let pickedImage = info[UIImagePickerControllerOriginalImage] as? UIImage{
let cropVC = TOCropViewController(image: pickedImage)
cropVC.delegate = self
cropVC.aspectRatioPickerButtonHidden = true
cropVC.aspectRatioPreset = .presetSquare
cropVC.aspectRatioLockEnabled = true
cropVC.resetAspectRatioEnabled = false
myPickerController?.pushViewController(cropVC, animated: true)
}
}
func cropViewController(_ cropViewController: TOCropViewController, didCropToImage image: UIImage, rect cropRect: CGRect, angle: Int) {
self.arrayOfCroppedImages.append(image)
dismiss(animated: true, completion: nil)
myPickerController = nil
}
}
我已经从文件中删除了很多代码,因为我无法看到任何其他相关内容。当我试图呈现UIImagePickerController
我设置了一个malloc_error_break断点,这就是我得到的
崩溃是完全随机的。大约有15%的可能性发生