我正在尝试在我的主视图控制器的子视图中创建一个uinavigationgroup。
catViewController *view = [[catViewController alloc] init];
UINavigationController *navCtrl = [[UINavigationController alloc] initWithRootViewController:view];
[_pageContainerView addSubview:navCtrl.view];
view.view.hidden = NO;
到目前为止这么好,我的子视图中有一个uinavigationcontroller,只是我想设置一个自定义左按钮来制作一个facebook风格的菜单,我必须有一个pan识别器和一个touchupinside,让我们从touchinside动作开始:
catViewController.m
- (void)viewDidLoad
{
[super viewDidLoad];
// set class variables
appDelegate = [[UIApplication sharedApplication] delegate];
// create button with touch handler
btn = [UIButton buttonWithType:UIButtonTypeCustom];
[btn setFrame:CGRectMake(0,0,42,33)];
if( [self.navigationController.viewControllers count] == 1 ){
[btn setImage:[UIImage imageNamed:@"btn_menu"] forState:UIControlStateNormal];
[btn addTarget:self action:@selector(btnMenuPress:) forControlEvents:UIControlEventTouchUpInside];
}else{
[btn setImage:[UIImage imageNamed:@"btn_back"] forState:UIControlStateNormal];
[btn addTarget:self action:@selector(btnBackPress:) forControlEvents:UIControlEventTouchUpInside];
}
// set the custom left button
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:btn];
}
- (IBAction)btnBackPress:(id)sender{
NSLog(@"back press");
}
- (IBAction)btnMenuPress:(id)sender{
NSLog(@"menu press");
}
到目前为止一切顺利,按钮就位,我的控制器可见,只有当我点击按钮时,我才得到一个线程1:EXC_BAD_ACCESS(Code = 1,address = 0x18)
所以现在我感到非常困惑,现在已经有4个多小时的时间来修补这个,现在是时候召唤骑兵了。
提前致谢!雷