我有一個需要管理多個視圖控制器的UINavigationController。導航控制器在下面的Take.m中,並且每個視圖控制器都在它自己的文件中(參見下面的CamverViewController.m)。作爲一名新的XCode開發人員,我試圖弄清楚如何構建應用程序,以便導航欄中按鈕的點擊等事件可以訪問導航控制器的實例以更改活動視圖控制器。我明白如何操作視圖控制器,但需要一些關於設置事件處理的建議。如何構建用於事件處理的UINavigation控制器和關聯的視圖控制器?
注意:我已經從示例源中刪除不相關的方法。
任何參考,樣品,建議,讚賞。
這個類是那裏的UINavigationController和頂級視圖控制器實例化。
Take.m源
@implementation Take
+ (UINavigationController*) createController {
//Controllers for navigation interface
CameraViewController *cameraViewController=[[CameraViewController alloc]init];
UINavigationController *navigationController=[[UINavigationController alloc]initWithRootViewController:cameraViewController];
navigationController.toolbarHidden=NO;
//Create tab bar item
[email protected]"Take";
UITabBarItem *tabBarItem=[[UITabBarItem alloc]initWithTitle:@"Take" image:NULL tag:0];
navigationController.tabBarItem=tabBarItem;
[navigationController.view.window addSubview:navigationController.view];
return navigationController;
}
@end
這是一種新的含有,點擊時/抽頭需要改變在導航控制器的視圖導航欄和右側按鈕的頂層視圖控制器。當這個事件被困時,主要問題是如何訪問Take.m中的導航控制器來操作活動視圖控制器? CameraViewController.m
@implementation CameraViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
//Navigation bar items
[self configureNavigationBarItems];
//Toolbar for navigation interface
[self configureToolbarItems];
}
return self;
}
-(void) configureNavigationBarItems{
//Add navigation bar items
// [navigationController setNavigationBarHidden:YES];
UIBarButtonItem *categorizeButton=[[UIBarButtonItem alloc]initWithTitle:@"Categorize" style:UIBarButtonItemStylePlain target:self action:@selector(categorizeButtonHandler:)];
self.navigationItem.rightBarButtonItem=categorizeButton;
}
-(void) configureToolbarItems{
UISegmentedControl *options=[[UISegmentedControl alloc]initWithItems:[NSArray arrayWithObjects:@"Photo",@"Video", nil]];
options.segmentedControlStyle=UISegmentedControlStyleBar;
options.selectedSegmentIndex=0;
[options addTarget:self action:@selector(toggleSorting:) forControlEvents:UIControlEventValueChanged];
UIBarButtonItem *optionButton=[[UIBarButtonItem alloc]initWithCustomView:options];
UIBarButtonItem *spacer=[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
self.toolbarItems=[NSArray arrayWithObjects:spacer,optionButton,spacer, nil];
}
#pragma mark - Event Handlers
- (void)categorizeButtonHandler:(id)sender
{
UIBarButtonItem *barButton=(UIBarButtonItem*)sender;
//How to access the navigation controller here???
}
@end