2012-09-30 7 views
1

각 UITableViewCell에 프로그래밍 방식으로 UISlider를 포함 시켰지 만,이 UISlider의 처음 2 개는 아래 이미지와 같이 항상 손상된 것으로 나타났습니다. UISlider가 손상됨

enter image description here

UISlider의 버튼의 일부

는 내가 처음으로 밀면을 남겼다됩니다. 다른 누구도 같은 문제를 경험 했습니까? 제 코드를 볼 필요가 있는지 말해주세요.

이 문제 외에도 UISlider 옆에 연결된 UIlabel이 잘 작동합니다.

세부 정보 : 내 cellForRowAtIndexPath 함수는 다음과 같습니다. UISlider를 추가하는 부분의 마지막 두 번째 단락을 찾으십시오. 나는 또한 셀에 슬라이더가 두 개 이상 추가 될지도 모른다고 생각했다. I는 각 슬라이더 만 회선의 NSLog 출력을 선택하여 한번 더해진다 것을 확인 :

NSLog(@"initiating slider at section %d row %d", indexPath.section, indexPath.row); 

부 및 행의 각 조합은 독특한!

필자도 테이블에있는 tableViewCell 행 수에 관계없이 상위 2 행의 UISliders 만 영향을 받는다는 것을 알게되었습니다.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
//creating a basic valid cell object 
static NSString *cellIdentifier = @"ActivitiesTVCcell"; 
UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:cellIdentifier]; 

if (!cell){ 
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier]; 
} 

if(indexPath.section == 0){ 
    NSArray *rowNames = [self.phpReply_ActivitiesTVC componentsSeparatedByString:@"\n"]; 
    cell.textLabel.text = [rowNames objectAtIndex:indexPath.row+2]; 
} 
else if (indexPath.section == 1){ 
    if (indexPath.row == 0) { 
     cell.textLabel.text = @"Seated"; 
    } 
    else if (indexPath.row == 1){ 
     cell.textLabel.text = @"Standing"; 
    } 
} 

cell.selectionStyle = UITableViewCellSelectionStyleNone; 



//start code addition of graph button stuff 
UIButton *graphButton = [UIButton buttonWithType:UIButtonTypeCustom]; 
[graphButton setFrame:CGRectMake(224, 0, 43, 37)]; 
[graphButton setBackgroundImage:[[UIImage imageNamed:@"graph icon.png"] stretchableImageWithLeftCapWidth:1.0 topCapHeight:1.0] forState:UIControlStateNormal]; 
[graphButton setBackgroundImage:[[UIImage imageNamed:@"graph icon.png"] stretchableImageWithLeftCapWidth:1.0 topCapHeight:1.0] forState:UIControlStateSelected]; 

[graphButton addTarget:self 
       action:@selector(graphButtonPressed:) 
     forControlEvents:UIControlEventTouchUpInside]; 
[cell addSubview:graphButton]; 
//end code addition of graph button stuff 


//start code addition of video button stuff 
UIButton *videoButton = [UIButton buttonWithType:UIButtonTypeCustom]; 
[videoButton setFrame:CGRectMake(300, 0, 43, 37)]; 
[videoButton setBackgroundImage:[[UIImage imageNamed:@"videoicon.png"] stretchableImageWithLeftCapWidth:1.0 topCapHeight:1.0] forState:UIControlStateNormal]; 
[videoButton setBackgroundImage:[[UIImage imageNamed:@"videoicon.png"] stretchableImageWithLeftCapWidth:1.0 topCapHeight:1.0] forState:UIControlStateSelected]; 

[videoButton addTarget:self action:@selector(videoButtonPressed:) forControlEvents:UIControlEventTouchUpInside]; 
[cell addSubview:videoButton]; 
//end code addition of video button stuff 


//start code for addition of enable switch 
UISwitch *activityEnableSwitch = [[UISwitch alloc] initWithFrame:CGRectMake(376, 7, 0, 0)]; //size components of CGRect are ignored 
[activityEnableSwitch setOn:NO animated:YES]; 
[activityEnableSwitch addTarget:self 
         action:@selector(enableSwitchStateChanged:) 
       forControlEvents:UIControlEventValueChanged]; 
[cell addSubview:activityEnableSwitch]; 
//end code for addition of enable switch 

//start code for addition of target angle text field 
UITextField *targetAngleTextField = [[UITextField alloc] initWithFrame:CGRectMake(476, 7, 50, 25)]; 
targetAngleTextField.borderStyle = UITextBorderStyleRoundedRect; 
targetAngleTextField.font = [UIFont systemFontOfSize:15]; 
targetAngleTextField.textColor = [UIColor blackColor]; 
targetAngleTextField.placeholder = @"30"; 
targetAngleTextField.autocorrectionType = UITextAutocorrectionTypeNo; 
targetAngleTextField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter; 
targetAngleTextField.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter; 
targetAngleTextField.keyboardType = UIKeyboardTypeNumberPad; //no num pad on ipad :(
//[targetAngleTextField becomeFirstResponder]; 
targetAngleTextField.delegate = self; 

[cell addSubview:targetAngleTextField]; 
//end code for addition of target angle text field 

//start code for addition of degree text label 
UILabel *degreeLabel = [[UILabel alloc] initWithFrame:CGRectMake(532, 6, 10, 10)]; 
degreeLabel.text = @"o"; 
degreeLabel.font = [UIFont systemFontOfSize:10]; 
[cell addSubview:degreeLabel]; 
//end code for addition of degree text label 

//start code for addition of progression level UISlider 
NSLog(@"initiating slider at section %d row %d", indexPath.section, indexPath.row); 
UISlider *progressionLevelSlider = [[UISlider alloc] initWithFrame:CGRectMake(576, 7, 150, 25)]; 
progressionLevelSlider.minimumValue = 0; 
progressionLevelSlider.maximumValue = 9; 
progressionLevelSlider.continuous = YES; 
progressionLevelSlider.value = 3; 

[progressionLevelSlider addTarget:self 
      action:@selector(progressionSliderValueChanged:) 
forControlEvents:UIControlEventValueChanged]; 

[cell addSubview:progressionLevelSlider]; 
//end code for addition of progression level UISlider 

//start code for addition of level ? text label 
UILabel *progressionLevelLabel = [[UILabel alloc] initWithFrame:CGRectMake(782, 13, 10, 20)]; 
progressionLevelLabel.text = [NSString stringWithFormat:@"%d", 2]; 
progressionLevelLabel.font = [UIFont systemFontOfSize:17]; 
progressionLevelLabel.tag = 121; //tag represents this particular UIlabel, so that we can set it from outside this function. 
[cell addSubview:progressionLevelLabel]; 
//end code for addition of level ? text label 


[cell setTag:(indexPath.section)*100+indexPath.row]; 

return cell; 
} 

여기에 내 sliderValueChanged 함수가 있습니다. '손상'은 슬라이더를 드래그 한 후에 만 ​​볼 수 있으므로이 코드를 여기에 넣습니다 (값을 변경하기 위해).

-(void)progressionSliderValueChanged: (UISlider *)sender { 
int section = ([sender superview].tag)/100; 
int row = [sender superview].tag%100; 

int value = sender.value; 

NSLog(@"slider value at section %d row %d was slided to %d",section, row, value); 

UITableViewCell *superViewOfSlider = (UITableViewCell *)[sender superview]; 
UILabel *progressionLevelLabel = (UILabel *)[superViewOfSlider viewWithTag:121]; 
progressionLevelLabel.text = [NSString stringWithFormat:@"%d", value]; 
[superViewOfSlider addSubview:progressionLevelLabel]; 

}

+3

cellForRowAtIndexPath에서 셀에 여러 슬라이더를 추가하는 것이 거의 확실합니다. 슬라이더를 추가 할 코드를 포함하도록 질문을 편집하십시오. – jrturton

답변

0

셀이 재사용 될 때마다, 당신은 셀에 파단의 새로운 세트를 추가하고 있습니다. 하위 뷰를 생성하는 코드를 모두 작성한 다음 셀을 작성한 블록 내부로 이동하십시오. 블록이있는 이후에는 필요한 태그 만 찾아서 (예 : 태그 사용) 해당 하위 뷰의 값을 설정하면됩니다.