Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 11-03-2010, 10:57 AM   #1 (permalink)
Registered Member
 
Join Date: Apr 2010
Posts: 3
moomy is on a distinguished road
Default getting nested arrays into the tableview??

Hi all,

I am trying to build a two level table view, under which is a detail view. I am using a plist to load the data.

The problem is getting the nested arrays into the second table. At the moment it just crashes. I think it is something to do with using an array within the array but am not sure how to sort this out.

any help would be amazing. I'm kind of noobyish so sorry if this question is obvious.



here is the RootViewController

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

@implementation RootViewController

@synthesize tableDataSource, CurrentTitle, CurrentLevel;
 

- (void)viewDidLoad {
    [super viewDidLoad];
	
	if(CurrentLevel == 0) {

   	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 = @"Categories";
}
	else 
		self.navigationItem.title = CurrentTitle;	
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning]; 
}

#pragma mark Table view methods

- (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];
}


// 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] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] autorelease];
    }
    
    // Set up the cell...
	
	NSDictionary *dictionary = [self.tableDataSource objectAtIndex:indexPath.row];
	
	cell.textLabel.text = [dictionary objectForKey:@"Title"];

	
	cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    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) {
		
	NSString *myLabel = [dictionary objectForKey:@"Title"];
		
				
		
		DetailViewController *dvController = [[DetailViewController alloc] initWithNibName:@"DetailView" bundle:[NSBundle mainBundle]];
		dvController.myLabel = myLabel;
		
		dvController.title = [dictionary objectForKey:@"Title"];
		
		
		[self.navigationController pushViewController:dvController animated:YES];
		
		[dvController release];
		dvController = nil;
		
			
		
	}
	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


here is the DrillDownAppAppDelegate
Code:
#import "DrillDownAppAppDelegate.h"
#import "RootViewController.h"
//#import "QuotesTableViewController.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
and here is the plist file




<dict>
<key>Rows</key>
<array>
<dict>
<key>Title</key>
<string>ChildTitle1</string>
<key>Children</key>
<array>
<string>no 1</string>
<string>yes 2</string>
<string>yes 3</string>
<string>yes 4</string>
<string>yes 5</string>
<string>yes 6</string>
<string>yes 7</string>
<string>yes 8</string>
<string>yes 9</string>
<string>yes 11</string>
<string>yes 10</string>
<string>yes 12</string>
<string>yes 13</string>
<string>yes 14</string>
<string>yes 15</string>
</array>
</dict>



If anyone has any ideas at all that would be amazing and I would be very grateful indeed. Thanks.
moomy is offline   Reply With Quote
Reply

Bookmarks

Tags
array, nsarray, tableview, uitableview problem

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 346
12 members and 334 guests
7twenty7, chiataytuday, condor304, Creativ, Domele, dreamdash3, laureix68, LEARN2MAKE, mistergreen2011, mottdog, palme2elie, Paul Slocum
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,660
Threads: 94,119
Posts: 402,896
Top Poster: BrianSlick (7,990)
Welcome to our newest member, laureix68
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 01:25 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0