简单的详细信息视图有帮助吗?

发布于 2024-08-23 09:01:35 字数 255 浏览 5 评论 0原文

我在详细视图方面遇到了重大问题,希望有人能给我指出正确的方向。

我想向像 apples advancetableviewcells 这样的应用程序添加详细视图。因此,一旦您单击某个单元格,它就会带您进入详细视图。

唯一的问题是,它还必须将单元格中的数据加载到详细视图中。

我查看了许多网站和在线示例,我可以看到它是如何使用简单的表格完成的,但是当涉及到单个单元格和 .plist 中的数据时。我迷路了。

请任何帮助都会很棒。 谢谢

Im having major problems with Detail views and was hoping someone could point me in the right direction.

I would like to add a detail view to an app like apples advancetableviewcells. So once you click on a cell, it leads you to the detail view.

Only catch is, it has to load the data from the cell into the detail view also.

I've looked at allot of sites and allot of examples online, and I can see how it done with simple table but when it comes to individual cells and the data in the .plist. I'm lost.

Please any help would be great.
Thanks

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

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

发布评论

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

评论(2

你在看孤独的风景 2024-08-30 09:01:35

添加细节控制器并不难实现。在你的根视图中 - 我猜 - 你从上面提到的 plist 文件中收集所有数据,并按照你自己的标准对数据进行排序。为什么不在根视图控制器中创建一个 NSArray,其中包含每个单元格的 NSDictionary。在该字典中,您可以放置​​该对象的所有信息,例如标题、价格或其他信息。在您的详细控制器中,只需添加一个 NSDictionary 属性。
如果选择一个单元格,则会调用 didSelectRowAtIndexPath 方法。在此方法中,您将详细视图控制器中的 NSDictionary 属性设置为根视图控制器的 NSArray 中索引 indexPath.row 处的对象。

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    DetailViewController *myDetailController = [[DetailViewController alloc] initWithNibName:@"NibBame" bundle:nil];
    myDetailController.detailDict = [rootViewArray objectAtIndex:indexPath.row];
    [self.navigationController pushViewController:myDetailController animated:YES];
    [myDetailController release];
}

之后,特定单元格的所有数据现在都可以在详细视图控制器,您可以利用 NSDictionary 的优点,只需通过一个简单的键即可获取变量。例如:

- (void)viewDidLoad {
    self.title = [myDictionary valueForKey:@"specificKey"];
}

Adding a detail controller isn't that difficult to implement. In your root view - I guess - you collect all the data from your plist file you mentioned above and order the data after your own criterias. Why don't you create a NSArray in the root view controller which contains a NSDictionary for every cell. In that dictionary you put all the information like title, price or something else of that object. In your detail controller just add an NSDictionary property.
If you select a cell, the didSelectRowAtIndexPath method is called. In this method you set the NSDictionary property in the detail view controller as the object in the NSArray of your root view controller at the index indexPath.row

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    DetailViewController *myDetailController = [[DetailViewController alloc] initWithNibName:@"NibBame" bundle:nil];
    myDetailController.detailDict = [rootViewArray objectAtIndex:indexPath.row];
    [self.navigationController pushViewController:myDetailController animated:YES];
    [myDetailController release];
}

Afterwards all the data for the specific cell is now available in the detail view controller, and you can use the advantages of the NSDictionary and can get the variables just by a simple key. For example:

- (void)viewDidLoad {
    self.title = [myDictionary valueForKey:@"specificKey"];
}
寄意 2024-08-30 09:01:35

表格单元格需要从 UITableViewCell 子类化。您不必设置视图控制器的标题三次或更多次,它总是会被覆盖。您应该在 cellForRowAtIndex 方法中设置自定义单元格并设置单元格的属性。

The table cell needs to be subclassed from UITableViewCell. You don't have to set the title of the view controller three or more times, it is always overwritten. You should set up your custom cell in the cellForRowAtIndex method and set the properties of the cell.

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