UIViewController navigation

Discussion in 'iOS Programming' started by adamlah, Jul 15, 2008.

  1. adamlah macrumors newbie

    Jul 15, 2008
    I have a PageAViewController.m containing the following code..

    -(id)init {
     if (self = [super init]) {
      self.title = @"Page A";
      UIBarButtonItem *navButton = [[UIBarButtonItem alloc] initWithTitle:@"Page B" style:UIBarButtonItemStylePlain target:self action:@selector(doPush)];
      self.navigationItem = navButton;
     return self;
    -(void)loadView {
     PageAView *pageAView = [[PageAView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
     [self setView:pageAView];
    -(void)doPush {
     PageBViewController *pageBViewController = [[[PageBViewController alloc] init] autorelease];
     [self.navigationController pushViewController:pageBViewController animated:YES];
    This sets up a PageAView controlled by PageAViewController with a navigation button to initialize PageBViewController (that controls PageBView) and slide it over.

    Within PageAView I have a UIButton I also want to trigger the slide. I can't work out how to do this. I would imagine it to be something like...

    UIButton *button ........
    [button addTarget:self action:@selector([self.viewController doSlide]) forControlEvents:UIControlEventTouchUpInside];
    ..to call the function in PageAViewController. However I can't work this out.

    Thanks :)
  2. white89gt macrumors regular

    Jan 18, 2006
    Instead of trying to call the doSlide method in the PageAViewController from the PageAView, the easier thing to do would be to access the navigation controller from the application delegate and push the new view controller that way.

Share This Page