Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Andrey Krylov
4,052 PointsShowing two images in one ViewController picked with UIImagePickerController from different buttons
I created a ViewController (UIViewController) where I have two UIImageView (avatar and coverPhoto) and two UIButton. Clicking on the first button I call for an action sheet where I can choose between "taking photo from library" or "take a new image". It works.
When I click the second UIButton it has to do the same operation (calling for action sheet with two actions) but when I pick the image it replaces the first image.
I found the core of the problem in UIImagePickerController and I was trying with “tags” to identify which button invoke the action. But it doesn’t work.
Do you have any ideas how to implement it?
8 Answers
Andrew Chalkley
Treehouse Guest TeacherHey Andrey Krylov,
It looks like you've implemented a similar solution to what I did solving your problem. Here's a video for you and those interested on how to do something like this.
I've used tags and some custom Enums to allow a user to change 2 UIImageViews in one view controller, using one action and multiple buttons.
For anyone who's interested in Using Tags and Enums in iOS you can download the project files here and follow along.
Regards,
Andrew
Stefan Buttigieg
10,065 PointsDear Andrey! Personally I haven't understood the problem. Could you share with us some more information regarding your issue?
Thanks in advance :)!
Andrey Krylov
4,052 Pointsoh I am sorry I just mentioned that you replied. I have already fixed that problem.
The problem was with complexity to make "else if" condition inside UIImagePickerController. But I fixed it using typedef enum mwthod.
Bastian Schiller
20,873 PointsEven though I´m not coding IOS right now, i really like the reply.
+1 for TV Tutor Thursdays
Andrew Chalkley
Treehouse Guest TeacherThanks for taking a look.
Nathan Taylor
Courses Plus Student 1,517 PointsThis was an AMAZING demonstration to watch for someone still learning to code for iOS. Thank you so much, Andrew!
Andrew Chalkley
Treehouse Guest TeacherKeep up the good work Nathan!
Andrey Krylov
4,052 PointsGuys from TreeHouse just inspire to learn code, just sit and bleed in front of computer!
Andrew Chalkley
Treehouse Guest TeacherI think that voids your warrantee!
qvwzucovkm
8,080 PointsBoy things have changed since I watched my first VB6 screencast back in the day and thought, hey! but isn't this a fun way to spend some the time while you are not coding. Thanks to the TH team for their outstanding support.
Andrew Chalkley
Treehouse Guest TeacherThank you for being a student!
Khimberly Luyun
2,652 PointsHi can you provide a link to download the video? thanks!
Meek D
3,457 PointsAndrew Chalkley i used a uigesture recognizer but how can use tag with it
Andrey Krylov
4,052 PointsAndrey Krylov
4,052 PointsWow, guys! Thank you for a video.. Really it is amazing! Andrew THANK YOU!
Andrey Krylov
4,052 PointsAndrey Krylov
4,052 PointsBy the way I fixed that problem in another way.
header:
Andrey Krylov
4,052 PointsAndrey Krylov
4,052 Pointsand my .m-file:
Nevertheless, Andrew and TH team thank you for a video. You code is much objective and cleaner than mine.
Andrey. PS. I will ask more))
Andrew Chalkley
Treehouse Guest TeacherAndrew Chalkley
Treehouse Guest TeacherI'm glad you've found it useful!