pushViewController help

Discussion in 'iOS Programming' started by John Baughman, Feb 13, 2010.

  1. John Baughman macrumors member

    Joined:
    Oct 27, 2003
    #1
    I created a user interface a while ago using presentModalViewController to animate the view from the bottom up. Today I decided to change it so that it animates from right to left with pushViewController, but I can't figure out what I have to do make it work. I think it has to do with how I created the first View....

    Code:
    - (void)profile
    {
    
            ProfileViewController *profileViewController = [[ProfileViewController alloc] initWithNibName:@"ProfileViewController"	bundle:nil];
    	UINavigationBar *profileNavigationBar = [[UINavigationBar alloc] initWithFrame: CGRectMake(0,0,480,52)];
    	profileNavigationBar.autoresizingMask = UIViewAutoresizingFlexibleWidth;
    			
    	UINavigationItem *navItem = [[UINavigationItem alloc] initWithTitle: @"Traveler's Profile"];
    	navItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem: UIBarButtonSystemItemDone target:self action: @selector(profileDidDismiss)];
    
    	[profileNavigationBar pushNavigationItem: navItem animated: NO];
    	
    	[profileViewController.view addSubview:profileNavigationBar];
    	
    	[self presentModalViewController:profileViewController animated:YES];
    	
    	[profileViewController release];
    	[profileNavigationBar release];
    	[navItem release];
    }
    
    
    The above code executes when the user taps a "Profile" button in a view without a navigation bar. The view animates from the bottom up.

    The ProfileView is a TableView and when the user taps one of it's rows I am executing the following code...

    Code:
    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    	
    	if((indexPath.section == 1) && (indexPath.row == 0)){
    		LocationSearchViewController *locationSearchViewController = [[LocationSearchViewController alloc] initWithNibName:@"LocationSearchViewController"	bundle:nil];
    		locationSearchViewController.delegate = self;		
    		UITableViewCell *cell = [myTableView cellForRowAtIndexPath:indexPath];
    		locationSearchViewController.defaultLocation = cell.detailTextLabel.text;
    		
    		     //[self.navigationController  pushViewController:locationSearchViewController animated:YES];
    		[self presentModalViewController:locationSearchViewController animated:YES];
    
    		[locationSearchViewController release];
             }
    }
    
    
    
    Using presentModalView everything works as advertised with the locationSearchView animating from the bottom up.

    I thought all I needed to do to change the animation to be from right to left was to replace the presentModalViewController with pushViewController, which I have commented out in the above code sample. It does not work, however. I do not get any errors but when I tap the row nothing happens.

    Is this because I used presentModalViewController to display the profileView? What do I have to do to be able to have the profileView animate bottom up and the subsequent locationSearchViewController animate right to left.

    Thanks,

    John
     
  2. firewood macrumors 604

    Joined:
    Jul 29, 2003
    Location:
    Silicon Valley
  3. John Baughman thread starter macrumors member

    Joined:
    Oct 27, 2003
    #3
    Ahh, I think there in lies the problem. I don't see that I did. Looks like I just initiated a UINavigationBar and added it to the view as a subview then presented the view with presentModalController. I can't push another view onto a stack that doesn't exist.

    I think to do what I want to do I have to fundamentally change the way I am adding the navigation bar to the profileView.

    Thanks for your help, I think I can figure this one out from here.

    John
     

Share This Page