gpt4 book ai didi

objective-c - Rookie Obj-C 问题——选择的 UITableViewCell 在 UIView subview 中不显示任何数据

转载 作者:行者123 更新时间:2023-11-29 11:22:35 25 4
gpt4 key购买 nike

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

代码:

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

谢谢,

jack

最佳答案

问题似乎出在这一行上。

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

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

int storyIndex = indexPath.row;

关于objective-c - Rookie Obj-C 问题——选择的 UITableViewCell 在 UIView subview 中不显示任何数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6170815/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com