在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