【问题标题】:UIToolbarItem not selecting when inserted as subview of UIPickerViewUIToolbarItem 在作为 UIPickerView 的子视图插入时未选择
【发布时间】:2014-03-28 14:11:02
【问题描述】:

我有一个 UIPickerView,它有一个 UIToolbar 作为子视图放置。问题是当我单击 UIbarviewItem 时没有任何反应。我不知道为什么,但是如果我将 UIToolbar 作为子视图插入到主视图 ([self.view addSubview:toolbar]) 中,按钮可以正常工作,但不能作为 uIPickerView 的子视图?

这是我用来创建 uipickerview 和 uitoolabr 的代码:

dateRangePickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(0, CGRectGetHeight(self.view.frame)-200, CGRectGetWidth(self.view.frame), 220)];
dateRangePickerView.showsSelectionIndicator = YES;
dateRangePickerView.hidden = NO;
[dateRangePickerView reloadAllComponents];

dateRangePickerView.showsSelectionIndicator = YES;
dateRangePickerView.delegate = self;
dateRangePickerView.dataSource = self;
[dateRangePickerView setBackgroundColor:[UIColor whiteColor]];

[self.view addSubview:dateRangePickerView];

// Add toolbar
toolBar= [[UIToolbar alloc] initWithFrame:CGRectMake(0, -44, CGRectGetWidth(self.view.frame), 44)];
[toolBar setBarStyle:UIBarStyleDefault];
UIBarButtonItem *barButtonDone = [[UIBarButtonItem alloc] initWithTitle:@"Done"
                                                                  style:UIBarButtonItemStyleBordered target:self action:@selector(selectDateRange)];
toolBar.items = [[NSArray alloc] initWithObjects:barButtonDone,nil];
barButtonDone.tintColor=[UIColor blackColor];
[dateRangePickerView addSubview:toolBar];

谁能告诉我哪里出错了?

谢谢,

彼得

【问题讨论】:

  • just referthis site 希望能解决你的问题
  • 此代码已过期。我不能使用 inputaccessoryview,因为它是只读属性
  • uipickerView 不工作?
  • UIPickerView 很好。请阅读问题

标签: objective-c uipickerview uitoolbar subview addsubview


【解决方案1】:

我决定不向 UIPicker 添加子视图,而是将 UIPicker 和 UIToolbar 放在 UIView 中以将所有内容放在一起。

感谢大家的帮助:)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多