开发者

Using plist to populate a grouped table

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, ho开发者_开发知识库w 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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜