1

我有 UITableViewCell,单击它会显示从 .xib 文件加载的 UIView。当我单击单元格时,视图已成功显示,但是我想在视图元素中显示的数据不会显示。

代码:

 - (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];

}

我可以看到以下线条:

[[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]];

没有识别 dView 元素并因此成功设置数据,但我不明白如何解决这个问题?

谢谢,

杰克

4

1 回答 1

2

问题似乎出在这条线上。

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

这对于一个对象来说似乎是陌生的,UITableView因为它们映射到rowssections。由于我希望stories映射到当前行,我认为您storyIndex应该是 -</p>

int storyIndex = indexPath.row;
于 2011-05-29T22:49:08.667 回答