我有一个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];有人能告诉我我哪里错了吗?
谢谢,
彼得
发布于 2014-03-28 23:25:46
我决定不向UIPicker添加子视图,而是将UIPicker和UIToolbar放在一个UIView中,以便将所有内容放在一起。
感谢所有人的帮助:)
https://stackoverflow.com/questions/22715231
复制相似问题