2011-04-17 80 views
1

我建立的是在頂部導航三個按鈕之類的調用的應用程序。酒吧。我不想做標籤欄,因爲標籤中只有一個項目。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]; 
+0

我想你錯過了定義該方法/選擇器。 – itsaboutcode 2011-04-20 11:03:51

回答

2

您可能會丟失選擇名稱後冒號。我認爲只是在@選擇器(newObject)是一個沒有參數的方法的引用。 @selector(newObject :)可能會起作用。

+0

這是很久以前,但你是對的..所以謝謝! – 2012-03-24 15:01:40

+0

是的,我看到它已經老了,但我正在研究三個按鈕的問題,並發現了一個我過去曾經被咬過的問題。所以我覺得「很好,也許它仍然在困擾那個可憐的人」:D – 2012-03-24 16:31:06