I use core Data to store my image as NSdata
, so the image will be stored from another TableViewController
Now, I would try to put a image stored as a NSData
into the pickerView
var restaurants:Restaurant!
var imageArray = [NSData]()
var dataArray1 = [Int]()
override func viewDidLoad() {
super.viewDidLoad()
imageArray = [restaurants.image!]
for(var i = 0; i < 100; i++) {
dataArray1.append((Int)(arc4random() % 10))
}
resultLabel.text = ""
pickerView.delegate = self
pickerView.dataSource = self
}
@IBAction func buttonClicked(sender: AnyObject) {
pickerView.selectRow(Int(arc4random())%94 + 3, inComponent: 0, animated: true)
}
func pickerView(pickerView: UIPickerView, viewForRow row: Int, forComponent component: Int, reusingView view: UIView?) -> UIView {
let pickerImage = UIImageView()
if component == 0 {
_ = imageArray[(Int)(dataArray1[row])]
}
return pickerImage
}
it looks like the view below, but the image inside should be my NSData
files
http://www.appcoda.com.tw/wp-content/uploads/2015/08/emoji-slotmachine.gif
When I run it, it always shut down. I think the problem is that Array doesn't get the value from the Core Data? Really need help, please.