내 응용 프로그램에서 다음과 같은 기능을 구현했습니다. Tabelview 셀에는 선택기 뷰를 표시하는 클릭시 두 개의 단추가 포함되어 있습니다. 선택기 값을 uitabelview 해당 cell.label에 반영하지 않으면 여기 코드 .uitabelview 셀의 Pickerview 값
의 tableview 세포
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];
[email protected]"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"])
{
}
}
이해야 내가 만든 피커 뷰 코드 내 코드? 제발 도와주세요.
데이터 소스를 연결하고 올바르게 위임을 했습니까? –
피커 높이가 0 인 이유는 무엇입니까? 피커에 높이를 올려보세요. – Joshua
@Bhargavi 네, 제가 연결했습니다. –