在我的应用程序中,我实现了如下功能,Tabelview 单元格包含两个单击按钮,它显示选择器视图,当我选择选择器值时,它不会反映在 uitabelview 对应的 cell.label 上,这里是代码。
表格视图单元格
if(tableView.tag==25)
{
static NSString *simpleTableIdentifier = @"ordercel";
ordercel *cell = (ordercel *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"ordercel" owner:self options:nil];
cell = [nib objectAtIndex:0];
}
cell.pimg.image=[arr objectAtIndex:indexPath.row];
cell.sizlb.text=@"45";
cell.qtylb.text=[qtyary objectAtIndex:indexPath.row];
[cell.contentView addSubview:lbl1];
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.tag = indexPath.row+2000;
[button addTarget:self action:@selector(BtnPressed:) forControlEvents:UIControlEventTouchUpInside];
button.backgroundColor=[UIColor clearColor];
button.frame = CGRectMake(130, 20 , 70, 35);
button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
button.contentEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 0);
[button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[cell addSubview:button];
UIButton *button1 = [UIButton buttonWithType:UIButtonTypeCustom];
button1.tag = indexPath.row+4000;
[button1 addTarget:self action:@selector(sizPressed:) forControlEvents:UIControlEventTouchUpInside];
button1.backgroundColor=[UIColor clearColor];
button1.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
button1.contentEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 0);
button1.frame = CGRectMake(230, 20 , 70, 35);
[button1 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[cell addSubview:button1];
return cell;
}
按钮方法
-(void)BtnPressed:(UIButton*)sender
{
[self createActionSheet];
pickerType = @"qtypicker";
UIPickerView *chPicker = [[UIPickerView alloc] initWithFrame:CGRectMake(0.0, 44.0, 0.0, 0.0)];
chPicker.tag=sender.tag-2000;
chPicker.dataSource = self;
chPicker.delegate = self;
chPicker.showsSelectionIndicator = YES;
[actionSheet addSubview:chPicker];
}
选择器查看代码
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView {
return 1;
}
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
if ([pickerType isEqualToString:@"qtypicker"])
{
counti = [array count];
}
if ([pickerType isEqualToString:@"sizepicker"])
{
counti = [array1 count];
}
return counti;
}
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
NSString *string;
if ([pickerType isEqualToString:@"qtypicker"])
{
string = [array objectAtIndex:row];
}
if ([pickerType isEqualToString:@"sizepicker"])
{
string = [array1 objectAtIndex:row];
}
return string;
}
- (CGFloat)pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)component {
return 300;
}
- (void)pickerView:(UIPickerView *)thePickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
UITableViewCell *owningCell = (UITableViewCell*)[thePickerView superview];
NSIndexPath *pathToCell = [tabvu indexPathForCell:owningCell];
int index1=thePickerView.tag;//= thePickerView.tag-2000;
if ([pickerType isEqualToString:@"qtypicker"])
{
UILabel *obj=((UILabel *)[self.view viewWithTag:index1+1000]);
obj.text = [array objectAtIndex:row];
[qtyary addObject:obj.text];
[tabvu reloadData];
}
if ([pickerType isEqualToString:@"sizepicker"])
{
}
}
如何在选定的单元格上获取选定的选择器值。我应该在我的代码中进行哪些更改?请帮我整理一下