ios - Swift 2: Update UIImage Dictionary with UIImage() var from UIImagePicker -
i have 2 viewcontrollers. viewcontroller#1 contains uiimagepicker , viewcontroller #2 contains uiimage dictionary variable key. update dictionary array uiimage variable (var newimage = uiimage() )that passed viewcontroller#1.the array expecting string tried converting uiimage array string. confirmed image no luck.any ideas?
viewcontroller#1: class viewcontroller: uiviewcontroller,uinavigationcontrollerdelegate,uiimagepickercontrollerdelegate { let imagepicker = uiimagepickercontroller() var images = [uiimage]() var testimage = uiimage() @iboutlet weak var beaconone: uitextfield! @iboutlet weak var beacontwo: uitextfield! @iboutlet weak var backimage: uiimageview! @iboutlet weak var majorid2: uitextfield! @ibaction func pickphoto(sender: uibarbuttonitem) { imagepicker.allowsediting = true imagepicker.modalpresentationstyle = .popover imagepicker.sourcetype = .photolibrary imagepicker.delegate = self self.presentviewcontroller(imagepicker, animated: true, completion: nil) } func imagepickercontroller(picker: uiimagepickercontroller, didfinishpickingimage pickedimage: uiimage, editinginfo: [string : anyobject]?) { testimage = pickedimage self.dismissviewcontrolleranimated(true, completion: nil) print(images) } override func viewdidload() { super.viewdidload() } override func prepareforsegue(segue: uistoryboardsegue, sender: anyobject?) { let planvc = segue.destinationviewcontroller as! planagramviewcontroller planvc.newimage = testimage } } viewcontroller#2: // // viewcontroller.swift // beacontest // // created apple on 5/6/16. // copyright © 2016 apple. rights reserved. // // uses corelocation framework import uikit import corelocation class planagramviewcontroller: uiviewcontroller,cllocationmanagerdelegate,uiimagepickercontrollerdelegate,uinavigationcontrollerdelegate { @iboutlet weak var imageview: uiimageview! @iboutlet weak var testimageview: uiimageview! var newimage = uiimage() var beaconimages = [51098: uiimage(named: "plan_p"),21714: uiimage(named: "plan_m")] override func viewdidload() { super.viewdidload() let newvcmajorid = int(vcmajorid1) beaconimages.updatevalue(uiimage(named: "plan_p"), forkey: newvcmajorid!) let newvcmajorid2 = int(vcmajorid2) beaconimages.updatevalue(uiimage(named: "plan_m"), forkey: newvcmajorid2!) } }
here's should . grab (in code)the planogram view controller ui story board , send image new image , in view controller # 2 use value.
view controller #2
import uikit import corelocation class planagramviewcontroller: uiviewcontroller,cllocationmanagerdelegate,uiimagepickercontrollerdelegate,uinavigationcontrollerdelegate { @iboutlet weak var imageview: uiimageview! @iboutlet weak var testimageview: uiimageview! var newimage : uiimage? var beaconimages = [51098: uiimage(named: "image"),21714: uiimage(named: "image")] override func viewdidload() { super.viewdidload() beaconimages.updatevalue(newimage, forkey: 51098) beaconimages.updatevalue(newimage, forkey: 21714) imageview.image = beaconimages[21714]! testimageview.image = beaconimages[51098]! } }
view controller #1 change below function , remove prepare segue method .
func imagepickercontroller(picker: uiimagepickercontroller, didfinishpickingimage pickedimage: uiimage, editinginfo: [string : anyobject]?) { testimage = pickedimage self.dismissviewcontrolleranimated(true, completion: nil) images.append(testimage) let planvc = uistoryboard.init(name: "main", bundle: nil).instantiateviewcontrollerwithidentifier("planagram") as? planagramviewcontroller planvc?.newimage = testimage self.presentviewcontroller((planvc)! , animated: true, completion: nil) }
Comments
Post a Comment