我创建了NavigationItem,而BarButtonItem使用items.leftBarButtonItem来添加,而baritem的动作我使用@selector来处理,它可以编译得很好但是当我触摸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;
答案 0 :(得分:2)
@selector(doItAgain)
表示doItAgain方法不带参数,而您的方法需要1.要解决此问题,请在选择器名称中添加冒号:@selector(doItAgain:)