【问题标题】:iOS - Three buttons in Nav. Bar - not Tab BariOS - 导航中的三个按钮。栏 - 不是标签栏
【发布时间】: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


【解决方案1】:

您可能在选择器名称后缺少一个冒号。我认为只是放入 @selector(newObject) 是对没有参数的方法的引用。 @selector(newObject:) 可能会起作用。

【讨论】:

  • 是的,我看到它很旧,但是我正在研究三键问题,发现了一个我过去一直被咬的问题。所以我想“好吧,也许它仍然在困扰这个可怜的家伙”:D
猜你喜欢
  • 1970-01-01
  • 2023-03-16
  • 1970-01-01
  • 2015-04-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-12-05
  • 1970-01-01
相关资源
最近更新 更多