last day (18 days later) » 

5:00 PM
4
A: Swift - get UIImage from UIColllectionViewCell

tgrableYou could do something like this func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { imageToPass = images[indexPath.row] } Edit: As far as passing that image to your next view controller, one possible way is to add a property to your first and se...

 
I tried this and I want to pass it to another ViewController with a segue but the image is not showing up in the other Viewcontroller :/
i just edited my question
 
I just saw your edit and it looks like you're already doing what I suggested. If you put a breakpoint in prepare is that getting set before your segue happens?
 
I think it happens before, because I just added a print("test") inside prepare and it got printed
 
I've run into this before with segues but not in a while. If I remember what the issue was for me I'll update in here.
Is your segue from file owner to your next viewController or table view cell to your next viewController? I think setting it from file owner to your next viewController then calling performSegue(withIdentifier: "name here". sender: nil) after you set the image in didSelectItemAt should work.
 
my code works now actually
do you maybe know how i can access that image from another class?
 
5:01 PM
How do you want to access it?
from what other class?
 
it should be the image of a cell
inside my HomeViewController I have my ViewController and a class for a custom cell
the image is now inside the ViewController, but I also need it in my Cell Class
 
Stop me if i'm missunderstanding
Your cell should have a UIImageView
 
yep
 
then your viewcontroller should give an image file to that cell in cellForItemAt
meaning your view controller or viewmodel holds the actual image files
 
5:05 PM
I think your current set up is ok
 
my code is super messy
 
lol thats ok
 
I have 3 classes
you can ignore the mainWishlistCell- Class and the addItemCell Class
oh I actually have 4 :D
the important classes are Content Cell and ExampleViewController
I managed to get the image inside my ExampleViewController
but i would like to set the image inside my ContendCell Class to the picked image
I hope you get what I'm trying to say :D
 
I think so... hang while i read through your files
 
sure
any questions about the code?:D
 
5:16 PM
Is the idea that the user is adding a new image and you are trying to get that into your collectionview?
 
yes pretty much
the only thing I need now is to get the "pickedImage" from "ExampleViewController" to "ContentCell"
inside ContentCell I want to set v.image (set to UIImage(Named: "logoGroß") atm) to "pickedImage
 
So you'll want to update imageData and theData arrays then call theCollectionView.reloadData()
 
nonono
well yes
but that already happends
happens*
I just want to set the v.image inside of ContentCell to "pickedImage"
 
Oh... I gotcha
hang on
You could add a method like setUp(image: UIImage) {} in your cell class where you pass the actual image files in in cellForItemAt instead statically setting it when you init up the imageview
or just set cell.testImage.image in cellForItemAt
 
ill try the second option
that seems pretty straight forwardd
 
5:26 PM
That is probably the easiest option
 
doesn't work
hmm
it still shows the old image
 
did you remove v.image = UIImage(named: "logoGroß")
I would actually remove all that setup
 
but it should just overwrite it shouldn't it?
 
just do let testImage: UIImageView = UIImageView(frame: .zero)
I'm not 100% but you might be setting a sub image over to the image you are passing in
 
one sec
no that just messes everything up
not working
 
5:31 PM
Not building or just not showing up?
 
not showing up
 
If you do cell.testImage/backgroundColor = .cyan cellForItemAt do you at least see the imageView in each cell?
cell.testImage.backgroundColor = .cyan
 
wait I was stupid..
it works now
 
Ok cool
 
but there is actually another problem :D
 
5:33 PM
lol whats up
 
i have a collecionView where the user can add custom cells right
 
Just a heads up i've got about 10 more minutes before i have to head out for a meeting
 
the problem is that these cell dont get saved
really appreciate your help"
!
 
No prob... happy to help
 
so the user can add a custom cell once
 
5:35 PM
So you're saying if you leave the viewcontroller they are no longer there?
 
but if he does it again (moves to the other viewcontroller and back again) the old cell just get replaced
yes
 
It all depends on how you're navigating away from that view controller. If it's getting deallocated then yeah all thats going to get thrown out. If you're pushing one onto a navigation controller then popping back i would think it should still be there
 
show segue
both ways
 
So your're doing another show to go back?
 
ye
 
5:44 PM
You may actually just be adding new view controllers onto the stack
 
how can I solve this
 
Are you using a navigation conroller?
 
yep
 
then you shouldnt need any segue to get back that all built in already
 
I am using a segue to pass the data
i thought it was easier that way
 
5:47 PM
just do the show to get to where you pick the image the call pop on the navigationController after you have your image
Oh shoot
you need to give the image back to the controller
 
?
yes :D
 
This will take a little bit of research on your part but you will need to use delegation
your second view controller will have a protocol that your first view controller listens to
 
ok
ill try to find something
ill message you if I dont find anything
thanks :)
 
protocol secondViewControllerDelegate: AnyObject {
func passImage(image: UIIMage)
}
this lives in your second view controller
 
um
what do I do with that?
 
5:52 PM
extension viewControllerOne: secondViewControllerDelegate {
func passImage(image: UIIMage) {
// add new image here
}

}
this lives in view controller one with the collection view
update your data arrays the reload your data
there is more to it but that is the basic set up
I gotta head out now
good luck
 
alright, thanks
 

  last day (18 days later) »