iPad: multiple root(master) views in uisplitview

Discussion in 'iPhone/iPad Programming' started by spoolup, Jan 30, 2011.

  1. macrumors newbie

    Joined:
    Sep 1, 2010
    #1
    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....
     
  2. Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #2
    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.
     
  3. thread starter macrumors newbie

    Joined:
    Sep 1, 2010
    #3
    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?
     
  4. Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #4
    Um, what's in there now?
     
  5. thread starter macrumors newbie

    Joined:
    Sep 1, 2010
    #5
    Code:
    detailViewController.detailItem = [[wxData objectAtIndex:indexPath.section] objectAtIndex: indexPath.row];	
    I'm using an NSMutableArray to populate my tables...
     
  6. Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #6
    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?
     
  7. thread starter macrumors newbie

    Joined:
    Sep 1, 2010
    #7
    here's the whole .m file

    Code:
    @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
     
  8. macrumors 603

    Joined:
    Aug 9, 2009
    #8
    Post the .h file, too. Without it, no one can see where or how the variables like wxData are declared.
     
  9. thread starter macrumors newbie

    Joined:
    Sep 1, 2010
    #9
    .h

    Code:
    @class DetailViewController;
    
    @interface NewNavViewController : UITableViewController {
        DetailViewController *detailViewController;
    	NSMutableArray *wxData;
    	NSMutableArray *wxSections;
    }
    
    -(void) createWxData;
    
    @property (nonatomic, retain) IBOutlet DetailViewController *detailViewController;
    
    @end
     
  10. Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #10
    So, where does detailViewController get assigned a value?
     
  11. thread starter macrumors newbie

    Joined:
    Sep 1, 2010
    #11
    that's actually word for word from a tutorial in a book :eek:
     
  12. macrumors 603

    Joined:
    Aug 9, 2009
  13. thread starter macrumors newbie

    Joined:
    Sep 1, 2010
    #13
    sams teach yourself in 24 hrs....

    what's wrong with the question?
     
  14. Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #14
    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?
     

Share This Page