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![](https://ecs-static.teamtreehouse.com/assets/views/marketing/shared/community-banner-white-47072046c51352fe6a69f5e691ff5700b28bb11d45197d7bdf066d9ea3f72d0c.webp)
![Kieran Robinson](https://uploads.teamtreehouse.com/production/profile-photos/528852/micro_image.jpg)
Kieran Robinson
9,411 PointsUIButton within a custom cell
Hi, I have a custom UITableViewCell that has an imageView property and a button (showBigPhotoButton) I want to be able to press on the button and present a view controller modally that contains the cells image (from its imageView) on a larger view. Similar to the view controller shown on Sam Soffes 'detailViewController' on the photoBombers project. My problem is that i can't present the viewController from within the custom cells class. Any help is greatly appreciated, Kieran
6 Answers
![Thomas Nilsen](https://secure.gravatar.com/avatar/897eff05ae62fe42b8a2109867700453?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Thomas Nilsen
14,957 PointsI made a tiny example :) Hope this helps:
Mike Baxter
4,442 PointsCan you just pass your subclass of UITableViewCell a weak reference to the viewController (in this case, the UITableViewController, right?) after you initialize the custom cell? Your button can have a target-action pair with a method that tells your viewController to present a view controller modally.
![Kieran Robinson](https://uploads.teamtreehouse.com/production/profile-photos/528852/micro_image.jpg)
Kieran Robinson
9,411 Pointshow would you do this? We can use the diary app as an example? the UITableViewCell is called EntryCell, the UITableViewController is called entryListViewController, within the cell there is an imageView called mainImageView and the button (showPhotoButton) will display whatever image is in the cells mainImageView on a new viewController thanks!
![Ash Furrow](https://secure.gravatar.com/avatar/0ebf471a3ae8df42a84f93a7efbbdbd0?s=60&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Ash Furrow
Treehouse Guest TeacherIt's a little more complicated, I'm afraid. You'd have to set up some kind of callback from each cell to the view controller so that it may present the new modal VC. So you'd need to declare a new delegate protocol and a new property on each cell that points to an object that conforms to that protocol.
![Kieran Robinson](https://uploads.teamtreehouse.com/production/profile-photos/528852/micro_image.jpg)
Kieran Robinson
9,411 PointsI have got it to work thanks to thomas' solution! Thank you
![Thomas Nilsen](https://secure.gravatar.com/avatar/897eff05ae62fe42b8a2109867700453?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Thomas Nilsen
14,957 PointsUse a delegation pattern for this :)
![Thomas Nilsen](https://secure.gravatar.com/avatar/897eff05ae62fe42b8a2109867700453?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Thomas Nilsen
14,957 PointsIf you can share the project I can show you how you would go about doing this ;)
![Kieran Robinson](https://uploads.teamtreehouse.com/production/profile-photos/528852/micro_image.jpg)
Kieran Robinson
9,411 PointsThank you so much Thomas!! That cleared it right up!