PDA

View Full Version : UIViewController navigation




adamlah
Jul 15, 2008, 02:48 AM
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 :)



white89gt
Jul 16, 2008, 08:22 AM
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.