I create NavigationItem and a BarButtonItem use items.leftBarButtonItem to add to ,and the baritem's action i use @selector to deal with ,it can complie fine but when i touch the buttonitem ,it's crashed ..maybe the selector cause it . when i close ARC on config file ,it turns right ...why ? i was confused with ARC,anyone could tell me how to deal with it ?
@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;
}
//fixed version:
//old:
IGMainViewController *mview = [[IGMainViewController alloc] init];
[self.view addSubview:mview.view];
//fixed:
@property(strong,nonatomic) IGMainViewController *mview;