我建立的是在頂部導航三個按鈕之類的調用的應用程序。酒吧。我不想做標籤欄,因爲標籤中只有一個項目。iOS - Nav中的三個按鈕。酒吧 - 不是標籤欄
在下面的代碼,左鍵(編輯)工作正常。右鍵 - 卡片的鏈接也可以正常工作。但是愚蠢的添加按鈕,給我一個錯誤,它無法找到選擇(insertNewObject)。
如果我拿出我的自定義代碼並使用代碼說「工作在捏」,那麼..它的工作原理。
我很感激要麼知道我在做什麼錯,要麼處理手頭問題的另一種方式 - 鏈接到應用程序的另一部分。
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];
我想你錯過了定義該方法/選擇器。 – itsaboutcode 2011-04-20 11:03:51