【发布时间】:2014-10-28 20:23:10
【问题描述】:
在 tableview 按钮单击中创建 UIpickerview。当第一次单击每个按钮时,选择器要显示。如果我在另一个时间单击相同的按钮,选择器想要隐藏并获取选择器值。在这里我只把我的代码放在最后一个单元格索引完成的过程第一个单元格索引不起作用?我该如何解决这个问题帮助我!!!这里屏幕! 在全局中创建选择器
UIPickerView *myPickerView;` 和 tableview 中的访问
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return [_arr_tags count]; /// in tag array number of button count
}
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
/// create a button
UIImage *ButtonImagecmt = [UIImage imageNamed:@"orangeButton@2x.png"];
UIButton *myButtoncmt = [UIButton buttonWithType:UIButtonTypeRoundedRect];
myButtoncmt.frame = CGRectMake(10,50,90,35);
[myButtoncmt setBackgroundImage:ButtonImagecmt forState:UIControlStateNormal];
[myButtoncmt addTarget:self action:@selector(picker_select:)forControlEvents:UIControlEventTouchDown];
[cell addSubview:myButtoncmt];
flg=1; /// first time picker want to hide so flag set 1.
myPickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(120, 0, 160, 180)];
myPickerView.delegate = self;
myPickerView.showsSelectionIndicator = YES;
myPickerView.hidden=true;
[cell addSubview:myPickerView];
}
return cell;
}
- (IBAction)picker_select:(id)search
{
if (flg==1)
{
/// first time button clickt picker want to display
myPickerView.hidden=false;
flg=0;
}
else
{
/// secound time button click picker want to hide
myPickerView.hidden=true;
flg=1;
}
}
此代码仅在最后一个单元格中有效。想要在表格视图中的所有单元格中工作
【问题讨论】:
-
而不是检查'flg'使用按钮选择状态。我希望taht会更好。在这里它不起作用,因为所有单元格只有一个“flg”变量。
-
如何检查表格视图单元格中每个按钮单击的 flg。如何在 tableview 中的每个单元格按钮中隐藏和显示pickerview 帮助我。
-
在您的 IBAction 中尝试重新加载 tableView,因为目前您正在设置 myPickerView.hidden 但我看不到您正在刷新 tableView。希望这会有所帮助。
-
我想在每次单击单元格按钮时隐藏选择器。如果我点击第一个单元格按钮最后一个单元格选择器隐藏和显示它的工作最后一个单元格..每个单元格按钮点击选择器想要隐藏和显示..我怎样才能获得帮助???
-
tabeview relaod 不工作