Iphone 添加leftBarButtonItem会崩溃
因此,我试图通过以下代码将我的LeftBarButtonim设置为我的导航项:Iphone 添加leftBarButtonItem会崩溃,iphone,objective-c,ios,ipad,Iphone,Objective C,Ios,Ipad,因此,我试图通过以下代码将我的LeftBarButtonim设置为我的导航项: UIBarButtonItem * leftSpacer = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil]; self.navigationItem.hidesBackButton = YES; leftSpacer.width
UIBarButtonItem * leftSpacer = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
self.navigationItem.hidesBackButton = YES;
leftSpacer.width = 10;
self.navigationItem.leftBarButtonItem = leftSpacer;
然而,它给了我一个收到SIGABRT的程序。为什么会这样?使用一些可能对您有所帮助的代码
// create the array to hold the buttons, which then gets added to the toolbar
NSMutableArray* buttons = [[NSMutableArray alloc] initWithCapacity:3];
// create a standard "add" button
UIBarButtonItem* bi = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:NULL];
bi.style = UIBarButtonItemStyleBordered;
[buttons addObject:bi];
// create a spacer
bi = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
[buttons addObject:bi];
// create a standard "refresh" button
bi = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:self action:@selector(refresh:)];
bi.style = UIBarButtonItemStyleBordered;
[buttons addObject:bi];
// stick the buttons in the toolbar
[tb setItems:buttons animated:NO];
// and put the toolbar in the nav bar
self.navigationItem.LeftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:tb];
代码示例显示alloc和init bar按钮项,但不显示发布。你会释放它吗<代码>[左侧垫片释放]这里没有错误。所以我们需要更多的背景。你在哪里做的?为什么不发布它会使应用程序崩溃,它只会泄漏它?我不太了解alloc和releas,只知道如果arc在中打开,我会发出警告和错误,而我没有,所以我认为这段代码是正确的。