2014-11-01 4 views
0

내 확인란을 변경하지 않은 행을 선택할 때 테이블보기에 사용자 지정 확인란이 만들어졌습니다. 나에게 도움을 주시기 바랍니다표보기 셀에 확인란을 추가하는 방법은 무엇입니까?

내 코드 : 사전에

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 

@try { 
    static NSString *CellIdentifier = @"Cell"; 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

    if (cell == nil) { 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 


      checkButton = [UIButton buttonWithType:UIButtonTypeCustom]; 
      [checkButton setFrame:CGRectMake(5, 5, 20, 20)]; 
      [cell addSubview:checkButton]; 

      pLblCabType = [[UILabel alloc]initWithFrame:CGRectMake(30, 5, 200, 20)]; 
      [cell addSubview:pLblCabType]; 

      pLblTariff = [[UILabel alloc]initWithFrame:CGRectMake(240, 5, 80, 20)]; 
      [cell addSubview:pLblTariff]; 

    } 



     [checkButton setImage:[UIImage imageNamed:[pArrImgBullet objectAtIndex:indexPath.row]] forState:UIControlStateNormal]; 
     pLblCabType.text = @"Arul"; 
     pLblTariff.text = @"Rs.1250"; 


    return cell; 

} 
@catch (NSException *exception) { 

    NSLog(@"Exception Error is %@",exception); 
} 
@finally { 

    } 
} 

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 

@try { 




     [checkButton setImage:[UIImage imageNamed:@"Bullet_Select.png"] forState:UIControlStateSelected]; 
     [pArrImgBullet replaceObjectAtIndex:indexPath.row withObject:@"Bullet_Select.png"]; 


    } 

} 
@catch (NSException *exception) { 
    NSLog(@"Exception Error is %@",exception); 

} 
@finally { 

    } 
} 

감사합니다, S.Arul

+0

여기서'checkButton''pLblCabType''pLblTariff'를 정의하고 있습니까? 대기열에서 제외 된 다음 셀 뷰에서 하위 뷰를 제거하는 이유는 무엇입니까? –

+0

셀 체크에 PLblCabType, PlblTariff 체크 버튼을 생성 중입니다. –

+0

UITableViewCell의 하위 클래스를 만들었습니까? –

답변

0

당신은 사용자 정의를 만들어야합니다 셀보기 적절한 방법으로 단추 및 기타 레이블을 추가 할 수 있습니다. 여러 가지 방법이 있습니다. 스토리 보드 (원한다면)를 사용하는 경우 프로토 타입 셀을 만드는 방법은 tutorial을 확인하고 xib 파일을 사용하는 경우 this을 확인하십시오.

1

cellForRowAtIndexPath 방법 아래 수정 해보십시오 : -

- (UITableViewCell *)tableView:(UITableView *)tv cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
UITableViewCell *cell = [tv dequeueReusableCellWithIdentifier:@"CellWithSwitch"]; 
if (cell == nil) { 
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"CellWithSwitch"] autorelease]; 
    cell.selectionStyle = UITableViewCellSelectionStyleNone; 
    cell.textLabel.font = [UIFont systemFontOfSize:14]; 

     cell.accessoryType = UITableViewCellAccessoryCheckmark; 
} 

return cell; 
+0

답장을 보내 주셔서 감사합니다.하지만 셀 왼쪽에 맞춤식 글 머리 기호 유형 확인란이 필요합니다. –

관련 문제