PDA

View Full Version : iPad: multiple root(master) views in uisplitview




spoolup
Jan 30, 2011, 12:01 PM
Hey guys.
does anyone have a way to do this? or a sample?

i am trying to find a way to add another view to the master (left) side of the uisplitview.
After the second view is loaded (from a table selection), then we can select a row on this new view and update the detail view....

stuck....



dejo
Jan 30, 2011, 02:19 PM
One way would be to assign a new array of view controllers to the UISplitViewController's viewControllers property. Another way, since the master is a navigation controller, is to push a new view controller on its stack.

spoolup
Jan 30, 2011, 02:29 PM
i pushed a vc on the stack with no probs.
now i can't open my url in the detailview once i select a row in the new vc.
the new vc i pushed into the stack is from another app i made that did open the url in the detail view.
what do i need to change in the didselectrow delegate?

dejo
Jan 30, 2011, 02:31 PM
what do i need to change in the didselectrow delegate?
Um, what's in there now?

spoolup
Jan 30, 2011, 02:33 PM
detailViewController.detailItem = [[wxData objectAtIndex:indexPath.section] objectAtIndex: indexPath.row];

I'm using an NSMutableArray to populate my tables...

dejo
Jan 30, 2011, 02:35 PM
What does your new viewController know about detailViewController and wxData? That is, are both of these non-nil when the line you supplied is executed?

spoolup
Jan 30, 2011, 03:17 PM
@implementation NewNavViewController


@synthesize detailViewController;

- (void)viewDidLoad {
[self createWxData];
[super viewDidLoad];

}


/*
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
}
*/
/*
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
}
*/
/*
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
}
*/
/*
- (void)viewDidDisappear:(BOOL)animated {
[super viewDidDisappear:animated];
}
*/

// Ensure that the view controller supports rotation and that the split view can therefore show in both portrait and landscape.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}

#pragma mark -
#pragma mark Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)aTableView {
// Return the number of sections.
return [wxSections count];
}


- (NSInteger)tableView:(UITableView *)aTableView numberOfRowsInSection:(NSInteger)section {
// Return the number of rows in the section.
return [[wxData objectAtIndex:section] count];
}


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

static NSString *CellIdentifier = @"CellIdentifier";

// Dequeue or create a cell of the appropriate type.
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
// cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
cell.accessoryType = UITableViewCellAccessoryNone;
}

// Configure the cell.
[[cell textLabel] setText:[[[wxData objectAtIndex:indexPath.section] objectAtIndex: indexPath.row] objectForKey:@"name"]];
// Add subview to cells
[[cell detailTextLabel] setText:[[[wxData objectAtIndex:indexPath.section] objectAtIndex: indexPath.row] objectForKey:@"subtitle"]];
[[cell imageView] setImage:[UIImage imageNamed:[[[wxData objectAtIndex:indexPath.section] objectAtIndex: indexPath.row] objectForKey:@"picture"]]];
cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
return cell;
}

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
return [wxSections objectAtIndex:section];
}


- (void)createWxData {

NSMutableArray *pirep;

wxSections=[[NSMutableArray alloc] initWithObjects:
@"PIREPs",nil];

pirep=[[NSMutableArray alloc] init];

[pirep addObject:[[NSMutableDictionary alloc]
initWithObjectsAndKeys:@"Alaska",@"name",@"from aviationweather.gov",@"subtitle",
//@".png",@"picture",
@"http://aviationweather.gov/adds/data/pireps/pireps_AK_TB.gif",@"url",nil]];

wxData=[[NSMutableArray alloc] initWithObjects:
pirep,nil];

[pirep release];
}



/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
// Return NO if you do not want the specified item to be editable.
return YES;
}
*/


/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {

if (editingStyle == UITableViewCellEditingStyleDelete) {
// Delete the row from the data source
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:YES];
}
else if (editingStyle == UITableViewCellEditingStyleInsert) {
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
}
}
*/


/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
}
*/


/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
// Return NO if you do not want the item to be re-orderable.
return YES;
}
*/

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return 50.0;
}


#pragma mark -
#pragma mark Table view delegate

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

/*
When a row is selected, set the detail view controller's detail item to the item associated with the selected row.
*/
detailViewController.detailItem =
[[wxData objectAtIndex:indexPath.section]
objectAtIndex: indexPath.row]; //detailViewController.detailItem = [NSString stringWithFormat:@"Row %d", indexPath.row];

}


#pragma mark -
#pragma mark Memory management

- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];

// Relinquish ownership any cached data, images, etc. that aren't in use.
}

- (void)viewDidUnload {
// Relinquish ownership of anything that can be recreated in viewDidLoad or on demand.
// For example: self.myOutlet = nil;
}


- (void)dealloc {
[wxData release];
[wxSections release];
[detailViewController release];
[super dealloc];
}


@end

chown33
Jan 30, 2011, 03:28 PM
Post the .h file, too. Without it, no one can see where or how the variables like wxData are declared.

spoolup
Jan 30, 2011, 03:31 PM
@class DetailViewController;

@interface NewNavViewController : UITableViewController {
DetailViewController *detailViewController;
NSMutableArray *wxData;
NSMutableArray *wxSections;
}

-(void) createWxData;

@property (nonatomic, retain) IBOutlet DetailViewController *detailViewController;

@end

dejo
Jan 30, 2011, 03:43 PM
So, where does detailViewController get assigned a value?

spoolup
Jan 30, 2011, 04:00 PM
that's actually word for word from a tutorial in a book :o

chown33
Jan 30, 2011, 05:03 PM
Which book?

I suggest reading the following:
http://www.cocoadev.com/index.pl?HowToAskQuestions
http://www.mikeash.com/getting_answers.html

spoolup
Jan 30, 2011, 05:08 PM
sams teach yourself in 24 hrs....

what's wrong with the question?

dejo
Jan 30, 2011, 05:55 PM
what's wrong with the question?
Um, not even sure what your question is at this point.

But did you have an answer to my question concerning where detailViewController is assigned a value?