I have UITableViewCell which, when clicked displays a UIView loaded from a .xib file. When I click the cell the view is successfully displayed however the data I want to display in the view elements won’t display.
Code:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// Navigation logic
NSLog(@"didSelectRowAtIndexPath");
//Initialize a UIView that contains all the elements required to display the data
EventDescriptionView *dView = [[EventDescriptionView alloc] init];
//Set the data in the elements to the data contained in the xml
//Set up the cell
int storyIndex = indexPath.row;
[[dView name] setText:[[stories objectAtIndex: storyIndex] objectForKey: @"title"]];
[[dView date] setText:[[stories objectAtIndex: storyIndex] objectForKey: @"date"]];
NSLog(@"Index: %d", storyIndex);
[[dView image] setImage:[images objectAtIndex:storyIndex]];
//Display the UIView
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.view cache:YES];
[self.view addSubview:dView.view];
[UIView commitAnimations];
}
I can see the lines:
[[dView name] setText:[[stories objectAtIndex: storyIndex] objectForKey: @"title"]];
[[dView date] setText:[[stories objectAtIndex: storyIndex] objectForKey: @"date"]];
NSLog(@"Index: %d", storyIndex);
[[dView image] setImage:[images objectAtIndex:storyIndex]];
Aren’t recognising the dView elements and therefore successfully setting the data, but I don’t understand how to get round this?
Thanks,
Jack
The problem seems to be with this line.
This seems alien to a
UITableViewobject as they map torowsandsections. Since I am expectingstoriesto map to the current row, I think yourstoryIndexshould be –