我创建 NavigationItem 和 BarButtonItem 使用 items.leftBarButtonItem 添加到,并且我使用 @selector 处理的 baritem 的操作,它可以很好地编译但是当我触摸 buttonitem 时,它崩溃了..可能是选择器导致它。当我在配置文件上关闭 ARC 时,它向右转...为什么?我对ARC感到困惑,任何人都可以告诉我如何处理它?
@implementation IGMainViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
UINavigationBar *navBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, 340, 44)];
UINavigationItem *items = [[UINavigationItem alloc] init];
UIBarButtonItem *leftBtn = [[UIBarButtonItem alloc] initWithTitle:@"aa" style:UIBarButtonSystemItemAdd target:self action:@selector(doItAgain:)];
items.leftBarButtonItem = leftBtn;
[navBar pushNavigationItem:items animated:NO];
[self.view addSubview:navBar];
}
-(void)doItAgain:(id)sender
{
NSLog(@"sss");
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}
//固定版本:
//old:
IGMainViewController *mview = [[IGMainViewController alloc] init];
[self.view addSubview:mview.view];
//fixed:
@property(strong,nonatomic) IGMainViewController *mview;