首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >作为UIPickerView的子视图插入时,UIToolbarItem未选择

作为UIPickerView的子视图插入时,UIToolbarItem未选择
EN

Stack Overflow用户
提问于 2014-03-28 22:11:02
回答 1查看 115关注 0票数 0

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

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

代码语言:javascript
复制
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];

有人能告诉我我哪里错了吗?

谢谢,

彼得

EN

回答 1

Stack Overflow用户

发布于 2014-03-28 23:25:46

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

感谢所有人的帮助:)

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22715231

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档