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
NAUSHAD DARUWALLA
1,587 PointsPassing objects between views
Hello all, I am trying to pass the HomeworkItem object from one view to another using the prepareForSegue method using the following code, however it does not work. Can somebody please tell me what is wrong in this sample and what i need to fix? Thank you!
-
(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // Get the new view controller using [segue destinationViewController]. if ([[segue identifier]isEqualToString:@"changeHomeworkItem"]) {
changeHomeworkViewController* destination = [segue destinationViewController]; destination.homeworkItem = [self.homeworkObjectItem objectAtIndex:self.selectedRow.row]; }
// Pass the selected object to the new view controller. }
1 Answer
Dennis Walsh
5,793 PointsNaushad,
Is there a particular challenger that this question is associated with, if so can you post that? Are you sure that you are getting the correct element from the array (or whatever self.homeworkObjectItem is) that you suspect? If you want the indexPath you need to get that from your table view. You can also access the cell that was selected it if you need that as well:
//get the index path of the selected row NSIndexPath *indexPath = [self.homeworkObjectItem indexPathForSelectedRow];
//get the cell that was selected UITableViewCell* cell = [self.homeworkObjectItem cellForRowAtIndexPath:sender]