2013-05-22 4 views
0

내 응용 프로그램에서 다음과 같은 기능을 구현했습니다. 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

데이터 소스를 연결하고 올바르게 위임을 했습니까? –

+0

피커 높이가 0 인 이유는 무엇입니까? 피커에 높이를 올려보세요. – Joshua

+0

@Bhargavi 네, 제가 연결했습니다. –

답변

0

코드를 읽기가 어렵습니다. 그러나 이것이 길이어야합니다.

pickerView:(UIPickerView *)thePickerView didSelectRow 

방법은 배열 객체 [qtyary objectAtIndex:indexPath.row] 업데이트. 그런 다음 [tableView reloadData];으로 전화하면 cell.qtylb.text이 업데이트됩니다. 다른 레이블의 경우 또한 업데이트 할 배열이 필요합니다. 나는 이것이 효과가 있기를 바란다.

0

UITableViewCell *owningCell = (UITableViewCell*)[thePickerView superview]; 

ordercel *owningCell = (ordercel*)[thePickerView superview]; 

에 didSelectRow에 라인을 변경하려고 당신은 당신이있는 UITableViewCell 사용자 정의 셀의 셀 인스턴스를하지해야 on.Then 버튼을 넣어 사용하는 사용자 정의 세포가있는 경우 .

그리고 그것은 returning.Apply NSLog가 obj와 어떤 목적이 조건

if ([pickerType isEqualToString:@"qtypicker"]) 
{ 
    UILabel *obj=((UILabel *)[self.view viewWithTag:index1+1000]); 
    obj.text = [array objectAtIndex:row]; 
    [qtyary addObject:obj.text]; 
    [tabvu reloadData]; 
} 

에 인쇄 로그를보십시오.