【发布时间】:2018-01-10 19:29:11
【问题描述】:
2我正在处理下拉菜单,我正在动态创建按钮和下拉表格视图。当我单击第一个按钮时,最后一个 tableView 被打开。但我想打开特定的 tableView(一次我只想打开一个下拉菜单)。
float y = 0;
float x = (self.answersView.frame.size.width/2)+175;
float Iy = 0;
float Ix = 675;
float Tx = (self.answersView.frame.size.width/2)+175;
float Ty = 0;
for (int i=0; i<self.radioBtnTagArr.count; i++) {
self.dropdownBtn = [UIButton buttonWithType:UIButtonTypeSystem];
self.dropdownBtn.frame = CGRectMake(x, y+30, (self.answersView.frame.size.width/2)-200, 50);
[self.dropdownBtn setTitle:@"0" forState:UIControlStateNormal];
self.dropdownBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
[self.dropdownBtn setTitleColor:[UIColor colorWithRed:24/255.0 green:56/255.0 blue:131/255.0 alpha:1] forState:UIControlStateNormal];
self.dropdownBtn.titleLabel.font = [UIFont systemFontOfSize:25];
[self.dropdownBtn addTarget:self action:@selector(dropdownBtnTapMethod:) forControlEvents:UIControlEventTouchUpInside];
self.dropdownBtn.backgroundColor = [UIColor lightGrayColor];
[self.scrollView addSubview:self.dropdownBtn];
self.dropdownBtn.tag = [[self.btnTagArr objectAtIndex:i] intValue];
y = y+70;
self.dropdownImageView = [[UIImageView alloc]initWithFrame:CGRectMake(Ix, Iy+50, 20, 10)];
self.dropdownImageView.image = [UIImage imageNamed:@"dropdown.png"];
[self.answersView addSubview:self.dropdownImageView];
Iy = Iy+70;
self.dropdownTableView = [[UITableView alloc]initWithFrame:CGRectMake(Tx, Ty+80, (self.answersView.frame.size.width/2)-200, 50) style:UITableViewStylePlain];
self.content = @[ @"Monday", @"Tuesday", @"Wednesday",@"Thursday",@"Friday",@"Saturday",@"Sunday"];
self.dropdownTableView.delegate = self;
self.dropdownTableView.dataSource = self;
[self.answersView addSubview:self.dropdownTableView];
Ty = Ty+70;
self.dropdownTableView.hidden = YES;
}
//事件处理方法
- (void)dropdownBtnTapMethod:(UIButton *) sender {
if (self.dropdownTableView.hidden == YES) {
self.dropdownTableView.hidden = NO;
} else {
self.dropdownTableView.hidden = YES;
}
}
以及如何动态设置表格视图高度。
【问题讨论】:
-
你可以分享预期视图的屏幕截图吗?
-
什么是 answersView 以及这个视图是什么?
-
answersView 是 mainView 中的一个子视图。它也有滚动视图。
-
您可以使用 tableview 制作此视图。名称和图像添加为部分。单击部分,您可以隐藏和显示行。
-
当我单击第一个 btn 时,我只想打开第一个表,当我再次单击第一个 btn 时,我想关闭它。像这样我想要所有的包子......
标签: ios objective-c uitableview cocoa-touch uibutton