UIToolbarItem当插入作为UIPickerView的子视图时不会选择
问题描述:
我有一个UIPickerView,它有一个UIToolbar作为子视图。问题是当我点击UIbarviewItem时什么也没有发生。我不知道为什么,但如果我将UIToolbar作为子视图插入主视图([self.view addSubview:toolbar]
),按钮可以正常工作,但不能作为uIPickerView的子视图?UIToolbarItem当插入作为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];
有谁告诉我,我要去哪里错了?
感谢,
彼得
答
我决定的,而不是添加一个子视图到UIPicker,我把UIPicker和UIToolbar在一个UIView把一切都在一起。
感谢所有您的帮助:)
[只是referthis网站(http://www.tutorialspoint.com/ios/ios_ui_elements_picker.htm)我希望解决你的问题 – 2014-03-28 14:27:51
此代码是过时的。我无法使用inputaccessoryview,因为它是只读属性 –
uipickerView无法正常工作? – 2014-03-28 14:47:30