菜鸟 Obj-C 问题 - UITableViewCell 选定在 UIView 子视图中不显示任何数据
我有 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题似乎出在这一行。
这对于
UITableView
对象来说似乎很陌生,因为它们映射到rows
和sections
。由于我期望stories
映射到当前行,我认为您的storyIndex
应该是 –The problem seems to be with this line.
This seems alien to a
UITableView
object as they map torows
andsections
. Since I am expectingstories
to map to the current row, I think yourstoryIndex
should be –