2012-11-05 5 views
0

UITableView을 만드는 데 문제가 있습니다. 셀에 레이블과 스테퍼가 할당되어있어 셀에 할당되어 있지 않습니다.하나의 셀에있는 레이블이 iPhone 용 tableView에 표시되지 않습니다.

여기 코드는 누군가가 문제를 파악할 수 있기를 바랍니다. 케이스 4에 도착하면 셀에 lblVarsta가 표시되지 않고 스테퍼 만 표시됩니다. 나는 그것을 디버깅했고 값은 거기에 있지만 그 값을 가진 레이블은 볼 수 없다. 고맙습니다!

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *)indexPath 
{ 
static NSString *CellIdentifier = @"Cell"; 
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
UITextField *inputField; 

lblRasa = [[UILabel alloc]initWithFrame:CGRectMake(120, 12, 185, 30)]; 
lblCuloare = [[UILabel alloc]initWithFrame:CGRectMake(120, 12, 185, 30)]; 
lblJudet = [[UILabel alloc]initWithFrame:CGRectMake(120, 12, 185, 30)]; 
lbldate = [[UILabel alloc] initWithFrame:CGRectMake(120, 12, 185, 30)]; 

inputField = [[UITextField alloc]initWithFrame:CGRectMake(120, 12, 185, 30)]; 
inputField.adjustsFontSizeToFitWidth = YES; 
inputField.borderStyle = UITextBorderStyleRoundedRect; 
inputField.tag = indexPath.row; 
inputField.delegate = self; 


segmentedControl1 = [[UISegmentedControl alloc] initWithFrame:CGRectMake(220, 10, 100, 10)]; 
segmentedControl2 = [[UISegmentedControl alloc] initWithFrame:CGRectMake(220, 10, 100, 10)]; 

NSArray * segmentItems = [NSArray arrayWithObjects: @"Da", @"Nu", nil]; 


// UIDatePicker *pv = [[UIDatePicker alloc] init]; 
// UIActionSheet *uas = [[UIActionSheet alloc] initWithTitle:@"pv" delegate:self  cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Select", nil]; 
//  
// [uas addSubview:pv]; 

if (!cell) 
{ 
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellAccessoryNone reuseIdentifier:CellIdentifier]; 

} 

switch ([indexPath row]) 
{ 
    case 0: 
     cell.textLabel.text = @"Nume"; 
     inputField.text = dog?dog.title:@""; 
     [cell addSubview:inputField]; 
     break; 
    case 1: 
     cell.textLabel.text = @"Rasa"; 
     lblRasa.text = dog?dog.rasa:@""; 
     [cell addSubview:lblRasa]; 
     break; 
    case 2: 
     cell.textLabel.text = @"Culoare"; 
     lblCuloare.text = dog?dog.culoare:@""; 
     [cell addSubview:lblCuloare]; 
     break; 
    case 3:{ 
     cell.textLabel.text = @"Data nasterii"; 
     lbldate.text = dog?dog.data_nas:@""; 

     [cell addSubview:lbldate]; 
     [cell addSubview:actionSheet]; 
    break;} 
    case 4:{ 
     lblVarsta = [[UILabel alloc] initWithFrame:CGRectMake(120, 12, 185, 30)]; 
     stepper = [[UIStepper alloc] initWithFrame:CGRectMake(220, 10, 100, 10)]; 
     cell.textLabel.text = @"Varsta"; 
     //inputField.text = dog?[NSString stringWithFormat:@"%d",dog.varsta]:@""; 

     lblVarsta.text = @"3 ani"; 
     [stepper addTarget:self action:@selector(stepperValueChanged:) forControlEvents:UIControlEventValueChanged]; 


     [lblVarsta setTextColor:[UIColor whiteColor]]; 
     [lblVarsta setBackgroundColor:[UIColor clearColor]]; 
     //[lbl5 setTextAlignment:UITextAlignmentLeft]; 

     [stepper setStepValue:10]; 

     [cell addSubview:lblVarsta]; 
     [cell.contentView addSubview:stepper]; 
     break;} 
    case 5: 
     cell.textLabel.text = @"Proprietar"; 
     inputField.text = dog?dog.proprietar:@""; 
     [cell addSubview:inputField]; 
     break; 
    case 6: 
     cell.textLabel.text = @"Judet"; 
     lblJudet.text = dog?dog.judet:@""; 
     [cell addSubview:lblJudet]; 
     break; 
    case 7: 
     cell.textLabel.text = @"Adresa"; 
     inputField.text = dog?dog.adresa:@""; 
     [cell addSubview:inputField]; 
     break; 
    case 8:{ 
     cell.textLabel.text = @"Parinti"; 
     //inputField.text = dog?dog.parinti:@""; 
     //lblVarsta.text = [NSString stringWithFormat:@"%.f", stepper.value]; 

     segmentedControl1 = [[UISegmentedControl alloc] initWithItems: segmentItems]; 
    //   segmentedControl1.segmentedControlStyle = UISegmentedControlStyleBar; 
    //   segmentedControl1.selectedSegmentIndex = 0; 

     [segmentedControl1 addTarget:self action:@selector(segmentedControlIndexChanged:) forControlEvents:UIControlEventValueChanged]; 

     [cell.contentView addSubview:segmentedControl1]; 
     break;} 
    case 9: 
     cell.textLabel.text = @"Pedigree"; 
     segmentedControl1 = [[UISegmentedControl alloc] initWithItems: segmentItems]; 
     [segmentedControl1 addTarget:self action:@selector(segmentedControlIndexChanged:) forControlEvents:UIControlEventValueChanged]; 
     [cell.contentView addSubview:segmentedControl2]; 
     break; 
} 

return cell; 
} 
+0

잘못된 'cellForRowAtIndexPath' 구현입니다. 셀을 재사용 한 후에 이미 적어도 하나의 추가 된 뷰가있을 것이므로 하위 뷰 계층을 분명하게 만들려면 메서드를 재구성해야합니다. 'case 4 :'에 관해서는 기본 흰색 배경에 보이지 않는 흰색 텍스트 색상을 사용하고 있습니다. –

+0

은 셀 배경색이고 lblVarsta 배경색은 ?? – AppleDelegate

+0

AppleDelegate와 A-Live는 귀하의 조언에 대해 감사드립니다. A-Live는 초보자이기 때문에 몇 가지 힌트, 어쩌면 사이트 등을 제공 할 수 있습니까? 도와 주셔서 감사합니다. – alin

답변

0

당신이

[cell addSubview:lblVarsta]; 
    [cell.contentView addSubview:stepper]; 

및 lblVarsta = [UILabel의 ALLOC] initWithFrame : CGRectMake (120, 12, 185, 30)]; stepper = [[UIStepper alloc] initWithFrame : CGRectMake (220, 10, 100, 10)];

lblVarsta = [[UILabel alloc] initWithFrame:CGRectMake(120, 12, 100, 30)]; 
    stepper = [[UIStepper alloc] initWithFrame:CGRectMake(220, 10, 100, 10)]; 

를 다음과 같이 당신은 내용 없음에 모두 하위 뷰를 추가해야하고 자신의 프레임이 둘 다 표시 할 수 있도록해야 프레임과

 [cell.contentView addSubview:stepper]; 
    [cell.contentView addSubview:lblgarsta]; 

를 시도하지 말아 .

+0

Srikanth 고마워요! 이제 또 다른 문제가 있습니다. 내가 여기에 쓴 http://stackoverflow.com/questions/13238730/how-to-align-the-segmented-control-at-the-right-of-the-cell-of-the-tableview. 어쩌면 당신도 이것을 알아낼 수 있습니다. 좋은 하루 되세요! – alin

+0

나는 문제를 파악했다. 개체를 재정의하고 분할 된 컨트롤의 좌표를 잃어 버렸습니다. – alin

관련 문제