在tableview按钮点击创建UIpickerview。当第一次点击每个按钮时,选取器要显示。如果我在另一个时间点击相同的按钮,选择器想要隐藏并获取选择器值。在这里,我把我的代码只有最后一个单元索引完成过程第一个单元格索引不工作?我该如何解决这个问题帮助我!这里屏幕!在实现代码如下桌面视图按钮点击需要在iOS中pickerview
-(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:@"[email protected]"];
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;
}
}
'和接取此代码仅在最后一个单元格工作; 创建全球像
UIPickerView * myPickerView捡拾工具。要在所有的细胞工作表视图
而不是检查'flg'使用按钮选择状态。我希望这会更好。在这里它不工作,因为你只有一个'flg'变量的所有单元格。 – Exploring 2014-10-28 11:36:00
我如何检查每个按钮在表格单元格中的单击的flg。如何隐藏和显示每个单元格按钮中的pickerview点击tableview帮助我。 – Shalini 2014-10-28 11:44:48
在您的IBAction尝试重新加载tableView,因为此刻,您正在设置myPickerView.hidden,但是我看不到您正在刷新tableView。希望这可以帮助。 – Gismay 2014-10-28 12:05:18