开发者

Rookie Obj-C problem - UITableViewCell selected displays no data in UIView sub view

开发者 https://www.devze.com 2023-03-08 22:32 出处:网络
I haveUITableViewCell 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

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:[[st开发者_运维知识库ories 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.

int storyIndex = [indexPath indexAtPosition: [indexPath length] - 1];

This seems alien to a UITableView object as they map to rows and sections. Since I am expecting stories to map to the current row, I think your storyIndex should be –

int storyIndex = indexPath.row;
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号