views:

282

answers:

1

Hi there,

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.

A: 

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.

Nick Forge
Thanks for the reply. How would I add a new property to my view controller? I'm somewhat clueless when it comes to objective-c and the iPhone SDK. Cheers.
Jack Griffiths
If you're not sure how to add a property in Obj-C, I'd recommend that you buy a book on iPhone development, like [this one from the Pragmatic Programmers](http://pragprog.com/titles/amiphd/iphone-sdk-development), and try working through that. You'll probably have a whole string of questions between getting from where you are now to what you're trying to achieve, and a book like that will answer 90% of them through examples.
Nick Forge