使用 plist 填充分组表

发布于 2024-08-31 20:06:07 字数 318 浏览 4 评论 0原文

我想使用 plist 来填充我的分组表。我已经查看了 DrillDownSave 示例项目,但我仍然一无所知。尽管如此,我确实了解到我可以在那里存储层次结构之类的东西。

所以问题如下:

  1. 如何使用我的 plist 将新项目添加到我的分组表中?我目前正在向表中添加一个数组,并且我注意到数组对我来说并不是最好的选择。

  2. 当用户点击plist中的某个项目时,如何将视图推送到相应的项目?换句话说,如何将基于所选行(由 plist 生成)的视图推送到其下一个“视图”?

如果这有意义,请回复。 谢谢, 杰克。

I was wanting to use a plist to populate my grouped table. I've had a look at the DrillDownSave sample project, and I'm still none-the-wiser. Although, I did learn that I could store hierarchies and suchlike in there.

So here's the questions:

  1. How can I use my plist to add new items to my grouped table? I'm currently feeding the table with an array, and I've noticed that an array isn't going to be the best thing for me.

  2. When a user taps on an item in the plist, how can I push the view to the corresponding item? In other words, how can I push the view based on the selected row (which was generated by the plist) to it's next "view"?

If that makes any sense, please reply.
Thanks,
Jack.

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

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

发布评论

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

评论(1

李白 2024-09-07 20:06:07

要将数组的 plist 表示形式加载到实际的 NSArray 实例中,请使用:

NSString *plistPath; // Assume that this is valid

NSArray *plistArray = [NSArray arrayWithContentsOfFile:plistPath];

要“向下钻取”,您需要在 UITableViewDelegate中执行以下操作-tableView:didSelectRowAtIndexPath:indexPath 方法:

  • 创建一个新的视图控制器实例
  • 告诉新的 VC 您要“向下钻取”哪些数据或对象(通常通过设置属性)
  • 将 VC 推送到您的导航控制器

假设您要深入研究的对象是 Widget,并且您的 widget 数组存储在名为 widgets 的 ivar 中,您将添加一个 widget > 属性到您的详细视图控制器,然后执行如下操作:(

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    MyDetailViewController *detailViewController = [[MyDetailViewController alloc] init];
    detailViewController.widget = [widgets objectAtIndex:indexPath.row];
    [[self navigationController] pushViewController:detailViewController animated:YES];
    [detailViewController release];
}

这位于您的表视图委托中)

有关详细信息,请参阅 文档的这一部分

To load a plist representation of an array into an actual NSArray instance, use:

NSString *plistPath; // Assume that this is valid

NSArray *plistArray = [NSArray arrayWithContentsOfFile:plistPath];

To "drill down", you need to do the following in your UITableViewDelegate's -tableView:didSelectRowAtIndexPath:indexPath method:

  • Create a new View Controller instance
  • Tell the new VC what data or object you're "drilling down" to (usually by setting a property)
  • Push the VC onto your Navigation Controller

Assuming that the object you're drilling down onto is a Widget, and your array of widgets is stored in an ivar named widgets, you would add a widget property to your Detail View Controller, then do something like this:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    MyDetailViewController *detailViewController = [[MyDetailViewController alloc] init];
    detailViewController.widget = [widgets objectAtIndex:indexPath.row];
    [[self navigationController] pushViewController:detailViewController animated:YES];
    [detailViewController release];
}

(this goes in your Table View Delegate)

For more info, see this part of the documentation.

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