【发布时间】:2011-04-17 01:36:32
【问题描述】:
我正在构建一个需要顶部导航中的三个按钮的应用程序。酒吧。我不想做一个标签栏,因为标签中只有一个项目。
在下面的代码中,左侧按钮(编辑)工作正常。右键 - 卡片链接也可以正常工作。然而,愚蠢的添加按钮给了我一个错误,它找不到选择器(插入新对象)。
如果我取出我的自定义代码并使用“在紧要关头工作”的代码,那么......它可以工作。
如果我知道自己做错了什么,或者是另一种处理手头问题的方法 - 链接到应用程序的另一部分,我将不胜感激。
TIA。
/*
// THIS WORKS IN A PINCH
// Set up the edit and add buttons.
self.navigationItem.leftBarButtonItem = self.editButtonItem;
UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(insertNewObject)];
self.navigationItem.rightBarButtonItem = addButton;
[addButton release];
// END OF WHAT WORKS
*/
// create a toolbar to have two buttons in the right
UIToolbar* tools = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 105, 44.01)];
self.navigationItem.leftBarButtonItem = self.editButtonItem;
// create the array to hold the buttons, which then gets added to the toolbar
NSMutableArray* buttons = [[NSMutableArray alloc] initWithCapacity:3];
UIBarButtonItem* addButton = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(insertNewObject)];
addButton.style = UIBarButtonItemStyleBordered;
[buttons addObject:addButton];
[addButton release];
// create a standard "add" button
// create a flip button
UIBarButtonItem* flipButton = [[UIBarButtonItem alloc]
initWithTitle:@"Cards" style:UIBarButtonItemStyleBordered
target:self action:@selector(flipToFront)];
[buttons addObject:flipButton];
[flipButton release];
// stick the buttons in the toolbar
[tools setItems:buttons animated:NO];
[buttons release];
// and put the toolbar in the nav bar
UIBarButtonItem* rightButtonBar = [[UIBarButtonItem alloc] initWithCustomView:tools];
self.navigationItem.rightBarButtonItem = rightButtonBar;
[rightButtonBar release];
【问题讨论】:
-
我认为您错过了定义该方法/选择器。
标签: xcode ios4 uinavigationcontroller navbar