- (void)viewDidLoad {
[super viewDidLoad];
self.navigationItem.title = @"DETAILS";
_dict = [[NSMutableDictionary alloc]init];
arrProductTitle = [[NSMutableArray alloc]initWithObjects:@"title0",@"title1",@"title2",@"title3",@"title4",@"title5",@"title6",@"title7",@"title8",@"title9",@"title10",@"title11",@"title12",@"title13",@"title14",@"title15", nil];
arrProductVal = [[NSMutableArray alloc]initWithObjects:@"0",@"1",@"2",@"3",@"4",@"5",nil];}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return arrProductTitle.count-1;}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *MyIdentifier = @"Cell";
customCell *cell1=[tableView dequeueReusableCellWithIdentifier:MyIdentifier];
if (cell1 == nil)
{
cell1 = [[customCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MyIdentifier];
}
cell1.productTitleLabel.text =[arrProductTitle objectAtIndex:indexPath.row];
NSLog(@"%@",_dict);
NSLog(@"%@",[NSString stringWithFormat:@"%ld",(long)indexPath.row]);
if (_dict[[NSString stringWithFormat:@"%ld",(long)indexPath.row]]) {
cell1.productvalueTextfield.text =[_dict valueForKey:[NSString stringWithFormat:@"%ld",(long)indexPath.row]];
}
else {
cell1.productvalueTextfield.text = @"";
self.downPicker = [[DownPicker alloc] initWithTextField:cell1.productvalueTextfield withData:arrProductVal];
self.downPicker.tag = indexPath.row;
[self.downPicker addTarget:self action:@selector(measurementSelected:) forControlEvents:UIControlEventValueChanged];
[cell1.contentView addSubview:self.downPicker];
}
return cell1;}
-(void)measurementSelected:(id)dp {
NSString* selectedValue = [dp text];
NSString* selectedIndex = [NSString stringWithFormat:@"%ld",(long)[dp tag]];
[_dict setValue:[dp text] forKey:selectedIndex];
NSLog(@"_dict: %@",_dict);
NSLog(@"SELECTED TAG:::::::%ld",[dp tag]);
NSLog(@"SELECTED VALUE:::::::%@",selectedValue);
NSLog(@"SELECTED INDEX VALUEEEEEEEEEEE:::::::%ld",[dp selectedIndex]);}
https://github.com/gvniosdev/Dynamic-UItableview-with-Picker-Selection
私はまた、あなたが、このためのソリューションを持っているなら、私に知らせて、同じ感じました。前もって感謝します。 –
DownPickerをセル自体(customCellクラスのinitメソッド内)に直接追加してから、セル内にデリゲートを宣言し、VCをセルのデリゲートとして設定する必要があります。次に、downPickerが選択/タップされるたびに、デリゲートメソッドを呼び出して、セルのindexpathを使用してイベントを処理します。 –
私はそれがうまくいけば解決策を見つけましたが、それは別のアプローチです。 –