<error>:CGAffineTransformInvert:奇异矩阵。在cellForRowAtIndexPath中

时间:2015-05-14 09:19:23

标签: ios swift uiimagepickercontroller tableviewcell

我有tableViewCell with button来从imagePickerController加载照片。

这是imagePickerController的代码。我将tableViewCell索引作为标签发送到按钮,以找出单击此按钮的单元格。然后,当用户从图库中选择图像时,它会将此图像设置为加载按钮的背景,并将此图像保存到我选择的图像阵列中。

// get photo function
func getPhotoFromGallery(sender: UIButton){
    cellTag = sender.tag
    picker.allowsEditing = false
    picker.sourceType = .PhotoLibrary
    presentViewController(picker, animated: true, completion: nil)
}

func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [NSObject : AnyObject]) {
    var chosenImage = info[UIImagePickerControllerOriginalImage] as! UIImage
    let cell = tableView.cellForRowAtIndexPath(NSIndexPath(forRow: cellTag!, inSection: 0)) as! QuestionTableViewCell
    cell.photoImageView.setBackgroundImage(chosenImage, forState: UIControlState.Normal)
    photos[cellTag!] = chosenImage
    dismissViewControllerAnimated(true, completion: nil)
}

然后在cellForRowAtIndexPath中,我检查我的数组中的图像是默认的还是由用户选择并将其设置为按钮的背景。

// imageView style and target
cell.photoLoadingButton.layer.cornerRadius = 4.0
cell.photoLoadingButton.clipsToBounds = true
cell.photoLoadingButton.tag = indexPath.row
cell.photoLoadingButton.addTarget(self, action: "getPhotoFromGallery:", forControlEvents: UIControlEvents.TouchUpInside)

// set photo to imageView if exists else - default
if photos[indexPath.row] == UIImage(named: "camera")! {
    cell.photoLoadingButton.setBackgroundImage(UIImage(named: "camera")!, forState: UIControlState.Normal)
}
else {
    cell.photoLoadingButton.setBackgroundImage(photos[indexPath.row], forState: UIControlState.Normal)
}

一切正常但我认为我的方法很糟糕=(

然后,当我在tableView中选择一些图像并滚动表格时,我在日志中收到此消息:“:CGAffineTransformInvert:奇异矩阵。”。它显示在显示带有上传图像的新单元格时。

0 个答案:

没有答案