Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6663257
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:28:45+00:00 2026-05-26T02:28:45+00:00

I found a tutorial for a UITableView – Drill down table view, source code

  • 0

I found a tutorial for a UITableView – Drill down table view, source code, but I would like to add a little upgrade. My goal is to add grouped table view with 2 sections in level 0 (CurrentLevel == 0). So I started with:

  1. Change table view style (at RootViewController.xib) from Plain to Grouped. (Works fine).

  2. Changes at RootViewController.m:

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

to

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
if(CurrentLevel == 0)    
    return 2;
else
    return 1;
  1. Add new key to data.plist named: Other.

After that CurrentLevel 0 returns 2 sections with same data for objectForKey:@”Rows”. I don’t know hot to change

-(void)viewDidLoad, 
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section,
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

methods to load data from data.plist for my new key @”Other”, where key @”Other” means 2nd section of the table in CurrentLevel 0 table view.

This is the source code for:

DrillDownAppAppDelegate.h

//
//  DrillDownAppAppDelegate.h
//  DrillDownApp
//
//  Created by iPhone SDK Articles on 3/8/09.
//  Copyright www.iPhoneSDKArticles.com 2009. 
//

#import <UIKit/UIKit.h>

@interface DrillDownAppAppDelegate : NSObject <UIApplicationDelegate> {

    UIWindow *window;
    UINavigationController *navigationController;

    NSDictionary *data;
}

@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet UINavigationController *navigationController;

@property (nonatomic, retain) NSDictionary *data;

@end

DrillDownAppAppDelegate.m

//
//  DrillDownAppAppDelegate.m
//  DrillDownApp
//
//  Created by iPhone SDK Articles on 3/8/09.
//  Copyright www.iPhoneSDKArticles.com 2009. 
//

#import "DrillDownAppAppDelegate.h"
#import "RootViewController.h"


@implementation DrillDownAppAppDelegate

@synthesize window;
@synthesize navigationController;
@synthesize data;


- (void)applicationDidFinishLaunching:(UIApplication *)application {

    NSString *Path = [[NSBundle mainBundle] bundlePath];
    NSString *DataPath = [Path stringByAppendingPathComponent:@"data.plist"];

    NSDictionary *tempDict = [[NSDictionary alloc] initWithContentsOfFile:DataPath];
    self.data = tempDict;
    [tempDict release];

    // Configure and show the window
    [window addSubview:[navigationController view]];
    [window makeKeyAndVisible];
}


- (void)applicationWillTerminate:(UIApplication *)application {
// Save data if appropriate
}  


- (void)dealloc {
    [data release];
    [navigationController release];
    [window release];
    [super dealloc];
}

@end

RootViewController.h

//
//  RootViewController.h
//  DrillDownApp
//
//  Created by iPhone SDK Articles on 3/8/09.
//  Copyright www.iPhoneSDKArticles.com 2009. 
//

#import <UIKit/UIKit.h>

@interface RootViewController : UITableViewController {

NSArray *tableDataSource;
NSString *CurrentTitle;
NSInteger CurrentLevel;
}

@property (nonatomic, retain) NSArray *tableDataSource;
@property (nonatomic, retain) NSString *CurrentTitle;
@property (nonatomic, readwrite) NSInteger CurrentLevel;

@end

RootViewController.m

//
//  RootViewController.m
//  DrillDownApp
//
//  Created by iPhone SDK Articles on 3/8/09.
//  Copyright www.iPhoneSDKArticles.com 2009. 
//

#import "RootViewController.h"
#import "DrillDownAppAppDelegate.h"
#import "DetailViewController.h"

@implementation RootViewController

@synthesize tableDataSource, CurrentTitle, CurrentLevel;


- (void)viewDidLoad {
    [super viewDidLoad];

    if(CurrentLevel == 0) {

        //Initialize our table data source
        NSArray *tempArray = [[NSArray alloc] init];
        self.tableDataSource = tempArray;
        [tempArray release];

        DrillDownAppAppDelegate *AppDelegate = (DrillDownAppAppDelegate *)[[UIApplication sharedApplication] delegate];
        self.tableDataSource = [AppDelegate.data objectForKey:@"Rows"];

        self.navigationItem.title = @"Zvolte trasu";
    }
    else 
        self.navigationItem.title = CurrentTitle;   
}

#pragma mark Table view methods

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    if(CurrentLevel == 0)    
        return 2;
    else
        return 1;
}


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


// Customize the appearance of table view cells.
- (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];
    }

    // Set up the cell...


    NSDictionary *dictionary = [self.tableDataSource objectAtIndex:indexPath.row];
    cell.textLabel.text = [dictionary objectForKey:@"Title"];
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    UIImage *rowImage = [UIImage imageNamed:[dictionary objectForKey:@"Image"]];
    cell.imageView.image = rowImage;

    return cell;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

    //Get the dictionary of the selected data source.
    NSDictionary *dictionary = [self.tableDataSource objectAtIndex:indexPath.row];

    //Get the children of the present item.
    NSArray *Children = [dictionary objectForKey:@"Children"];

    if([Children count] == 0) {

        DetailViewController *dvController = [[DetailViewController alloc] initWithNibName:@"DetailView" bundle:[NSBundle mainBundle]];
        [self.navigationController pushViewController:dvController animated:YES];
        [dvController release];
    }
    else {

        //Prepare to tableview.
        RootViewController *rvController = [[RootViewController alloc] initWithNibName:@"RootViewController" bundle:[NSBundle mainBundle]];

        //Increment the Current View
        rvController.CurrentLevel += 1;

        //Set the title;
        rvController.CurrentTitle = [dictionary objectForKey:@"Title"];

        //Push the new table view on the stack
        [self.navigationController pushViewController:rvController animated:YES];

        rvController.tableDataSource = Children;

        [rvController release];
    }
}

- (void)dealloc {
    [CurrentTitle release];
    [tableDataSource release];
    [super dealloc];
}

@end

Edit:

My attempt:

RootViewController.h

//
//  RootViewController.h
//  DrillDownApp
//
//  Created by iPhone SDK Articles on 3/8/09.
//  Copyright www.iPhoneSDKArticles.com 2009. 
//

#import <UIKit/UIKit.h>

@interface RootViewController : UITableViewController {

NSArray *tableDataSource;
    NSArray *otherDataSource;
NSString *CurrentTitle;
NSInteger CurrentLevel;
}

@property (nonatomic, retain) NSArray *tableDataSource;
@property (nonatomic, retain) NSArray *otherDataSource;
@property (nonatomic, retain) NSString *CurrentTitle;
@property (nonatomic, readwrite) NSInteger CurrentLevel;

@end

RootViewController.m

//
//  RootViewController.m
//  DrillDownApp
//
//  Created by iPhone SDK Articles on 3/8/09.
//  Copyright www.iPhoneSDKArticles.com 2009. 
//

#import "RootViewController.h"
#import "DrillDownAppAppDelegate.h"
#import "DetailViewController.h"

@implementation RootViewController

@synthesize tableDataSource, otherDataSource, CurrentTitle, CurrentLevel;


- (void)viewDidLoad {
    [super viewDidLoad];

    if(CurrentLevel == 0) {

        //Initialize our table data source
    NSArray *tempArray = [[NSArray alloc] init];
    self.tableDataSource = tempArray;
    self.otherDataSource = tempArray;
            [tempArray release];

    DrillDownAppAppDelegate *AppDelegate = (DrillDownAppAppDelegate *)[[UIApplication sharedApplication] delegate];
    self.tableDataSource = [AppDelegate.data objectForKey:@"Rows"];
    self.otherDataSource = [AppDelegate.data objectForKey:@"Other"];

    self.navigationItem.title = @"Root";
}
else 
    self.navigationItem.title = CurrentTitle;   
}

#pragma mark Table view methods

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    if(CurrentLevel == 0)
        return 2;
    else
        return 1;
}


// Customize the number of rows in the table view.
//Not sure about this. When I select some cell from section 1, what will appear at didSelectRowAtIndexPath?
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if(section == 0 && CurrentLevel == 0)
        return [self.tableDataSource count];
    if(section == 1 && CurrentLevel == 0)
        return [self.tableDataSource count];
    else 
        return [self.tableDataSource count];
}

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {

    if(section == 0 && CurrentLevel == 0)
        return nil;
    else
        return nil;
}


// Customize the appearance of table view cells.
- (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];
    }

    // Set up the cell... don't know how.

    //here is only tableDataSource
    NSDictionary *dictionary = [self.tableDataSource objectAtIndex:indexPath.section];
    cell.textLabel.text = [dictionary objectForKey:@"Title"];
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    UIImage *rowImage = [UIImage imageNamed:[dictionary objectForKey:@"Image"]];
    cell.imageView.image = rowImage;

    return cell;
}

//same problem
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

    //only tableDataSource
    NSDictionary *dictionary = [self.tableDataSource objectAtIndex:indexPath.row];

    //Get the children of the present item.
    NSArray *Children = [dictionary objectForKey:@"Children"];

    if([Children count] == 0) {

        DetailViewController *dvController = [[DetailViewController alloc] initWithNibName:@"DetailView" bundle:[NSBundle mainBundle]];

        [self.navigationController pushViewController:dvController animated:YES];
        [dvController release];
    }
    else {

        //Prepare to tableview.
        RootViewController *rvController = [[RootViewController alloc] initWithNibName:@"RootViewController" bundle:[NSBundle mainBundle]];

        //Increment the Current View
        rvController.CurrentLevel += 1;

        //Set the title;
        rvController.CurrentTitle = [dictionary objectForKey:@"Title"];

        //Push the new table view on the stack
        [self.navigationController pushViewController:rvController animated:YES];

        rvController.tableDataSource = Children;

        [rvController release];
    }
}

- (void)dealloc {
    [CurrentTitle release];
    [tableDataSource release];
    [otherDataSource release];
    [super dealloc];
}

@end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T02:28:46+00:00Added an answer on May 26, 2026 at 2:28 am
    • Create a second array to hold the data for the second section
    • Populate this array in viewDidLoad using your @”Other” key
    • Use indexPath.section in the relevant datasource methods so that you know which section your table view is asking you about, and return the object / count of the relevant array. indexPath.section will be 0 for the first section and 1 for the second section.
    • Wherever you are using tableDataSource, you need to check what section you are in. This is either passed in as an integer (section) or as part of the indexpath (so you can get it via indexPath.section). If you are in section 0, use tableDataSource, else if you are in section 1, use otherDataSource.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I found a tutorial from nettuts and it has a source code in it
I would like to build a Deskband for Internet Explorer. I found this tutorial
I found the following table structures while I was watching ruby on rails tutorial.
I found a tutorial for configuring server here http://www.organicdesign.co.nz/Simple_video_streaming_with_ffserver but it is for linux...
I found a tutorial with a demo on customizing the 'Facebook Like Box'; it
I have a drop down menu which I found a tutorial for. In Firefox
I found a tutorial to do syntax highlighting in RichEdits for WPF: http://blogs.microsoft.co.il/blogs/tamir/archive/2006/12/14/RichTextBox-syntax-highlighting.aspx But
I found this tutorial about Activex component but I am getting an error under
This might be a stupid question but i failed to do through tutorial found
I found this tutorial that explains what I want to do using html but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.