【问题标题】:Tool bar in IOS 6 not working properlyIOS 6 中的工具栏无法正常工作
【发布时间】:2014-02-18 15:14:51
【问题描述】:

我正在向 UIView 添加工具栏,例如:

 UIToolbar *toolbar = [[UIToolbar alloc] init];
    toolbar.frame = CGRectMake(0, 0, 300, 44);
    UIBarButtonItem *button1 = [[UIBarButtonItem alloc] initWithTitle:@"Send" style:UIBarButtonItemStyleDone target:self action:@selector(sendAction)];

    UIBarButtonItem *button2=[[UIBarButtonItem alloc]initWithTitle:@"Cancel" style:UIBarButtonItemStyleDone target:self action:@selector(cancelAction)];

    [toolbar setItems:[[NSArray alloc] initWithObjects:button1, nil]];
    [toolbar setItems:[[NSArray alloc] initWithObjects:button2, nil]];
    [self.view addSubview:toolbar];

但是按钮总是处于禁用状态..我不知道为什么总是会发生这种情况。我也清理了我的项目。

【问题讨论】:

  • “禁用表单”是什么意思——你的意思是点击按钮不会运行操作方法吗?你看到两个按钮了吗?我认为您设置项目的代码应该是“[toolbar setItems:@[button1, button2];”。

标签: ios6 uiview uibarbuttonitem toolbar


【解决方案1】:

NSArray *toolbarItems = [NSArray arrayWithObjects: 按钮1,按钮2,无]; [self.toolbar addsubview:toolbaritems

添加这行代码

【讨论】:

  • 你错了。 [self.toolbar addsubview:toolbaritems];我们不能这样做,因为toolbaritems 是一个数组而不是UIView。
猜你喜欢
  • 2013-01-01
  • 2016-12-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-09-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多