ckc123inDC
ckc123inDC

Reputation: 125

Push different view controllers with plist populated table

Here is the code that I have in the viewcontroller that uses the plist information provided in my appdelegate.

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}


// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return [self.tableDataSource count];
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
    }


    NSDictionary *dictionary = [self.tableDataSource objectAtIndex:indexPath.row];
    cell.text = [dictionary objectForKey:@"myobject"];

This uses the plist that is used in the appdelegate and populates the cells in my table with exactly how many entrances I have in my plist.

The next thing I want to do is push a nondynamic viewcontoller for each cell populated with its corresponding "key".

So, the myobject cell (when selected) pushes the myobject viewcontroller. The yourobject cell (when selected) pushes the yourobject viewcontroller.

 All the way down.

How could I go about doing this?

Upvotes: 0

Views: 292

Answers (1)

Ray Wenderlich
Ray Wenderlich

Reputation: 480

  1. Have your main window contain a UINavigationController, and set the table view you described above as the root view controller.
  2. Have your table view contain a member variable for your secondary view controller that will be the "detail view" for that item. Initialize it somewhere (such as viewDidLoad).
  3. Have your detail view contain a member variable for the info to be displayed (i.e. the element in your dictionary). Let's call this myData.
  4. Implement didSelectRowAtIndexPath in your table view to detect when a row is selected. Here you'll look up the object from the dictionary based on the selected row, set it as myData on your detail controller, and use pushViewController on your navigation controller to push the new view onto the stack.

Hope this helps!

Upvotes: 1

Related Questions