【发布时间】:2014-09-17 08:25:34
【问题描述】:
我通过引用另一个类来传递我的 UINavigationController。但它显示错误 Address of property expression requested 。
MyUtil *util =[[MyUtil alloc] init];
[util NavAndBackBtn:&self.navigationController];// 此处报错..
MyUtil.m
-(void)NavAndBackBtn:(UINavigationController **)nav // ** for passing by reference
{
UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
[btn setImage:[UIImage imageNamed:@"icon_back.png"] forState:UIControlStateNormal];
[button setFrame:CGRectMake(0,0,36,20);
UIBarButtonItem *barbtn = [[UIBarButton alloc] initWithCustomView:btn];
//*nav.navigationController.navigationItem.leftBarButtonItem = barbtn;// this gives error
//then i set this nav to Util nav
self.main_nav_ofUtilClass = *nav;
sefl.main_nav_ofUtilClass.navigationItem.leftBarButtonItem =barbtn;
}
问题
如何通过引用传递 UINavigationController。 这样我在另一个类中对 UINavigationController 所做的任何更改都会发生在它身上。
我只是想在另一个类名 MyUtil 中向 UINavigationController 添加一个后退按钮图像
【问题讨论】:
-
如果添加按钮是目标,为什么不尝试使用类别?保留一个布尔值以在默认和自定义之间切换。
标签: ios uinavigationcontroller uibarbuttonitem