菜鸟 Obj-C 问题 - UITableViewCell 选定在 UIView 子视图中不显示任何数据

发布于 2024-11-10 16:11:55 字数 1475 浏览 4 评论 0原文

我有 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 元素,因此成功设置数据,但我不明白如何解决这个问题?

谢谢,

杰克

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

咋地 2024-11-17 16:11:55

问题似乎出在这一行。

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

这对于 UITableView 对象来说似乎很陌生,因为它们映射到 rowssections。由于我期望 stories 映射到当前行,我认为您的 storyIndex 应该是 –

int storyIndex = indexPath.row;

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;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文