2012-03-24 4 views
1

UITableViewCell에 UItextField를 배치하고 싶지만 문제가 있습니다. 텍스트 필드가 나타나지 않습니다. 이것은 내 코드입니다 :UITableViewCell의 UITextField

-(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString   *)reuseIdentifier { 
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; 
    if (self) { 
     self.textField = [[UITextField alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 120.0f, 45.0f)]; 
     self.textField.textColor = [UIColor blackColor]; 

     [self.contentView addSubview:self.textField]; 
    } 

    return self; 
} 


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *CellIdentifier = @"Cell"; 

    TextFieldCell *cell = (TextFieldCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     cell = [[TextFieldCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 
    } 
    switch (indexPath.row) { 
     case 1: 
      cell.textField.placeholder = @"Username"; 
      break; 
     case 2: 
      cell.textField.placeholder = @"Password"; 
      break; 
     case 3: 
      cell.textField.placeholder = @"Server Address"; 
      break; 
     case 4: 
      cell.textField.placeholder = @"Description"; 
      break;    
     default: 
      break; 
    } 

    return cell; 
} 

제가 테스트하고 initWithStyle 메서드가 호출됩니다. 누군가 나를 도와 줄 수 있습니까?

+1

작동합니다? cellForRowAtIndexPath에 textField의 text 속성 값을 설정하고 있습니까? – jonkroll

+0

예 NSLog를 사용해 보았습니다. 내 edtited 게시물을 참조하십시오. –

+1

'self.textField'에 대한 속성 선언을 보여줄 수 있습니까? – borrrden

답변

2

TextFieldCell 다음 드래그하여 텍스트 뷰를 삭제하고 모든 속성이 다른 당신이 *

에 의해 TableViewCell로 사용할 경우에만 * .XIB 를 만들 수 있습니다 인터페이스 빌더를 형성 설정을 위해 당신은 .xib 파일이있는 경우

.h 파일

IBOutlet UITableViewCell * CUSTOM_CELL_XIB; cellForRowAtIndexPath 방법에서하는 .m 파일에서

static NSString *CellIdentifier = @"Cell"; 


UITableViewCell *cell = (UITableViewCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

if (cell == nil) 
{ 
    [[NSBundle mainBundle] loadNibNamed:@"CUSTOM_CELL_XIB" owner:self options:nil]; 
    cell = CUSTOM_CELL_XIB; 
} 

직접 드래그 앤 당신이 원하는에 textField 또는 어떤 UI를 드롭, 나는 그것이 사용자 정의 셀 생성을위한 효율적인 방법이라고 생각합니다. 당신이 그것을 호출지고 있는지 확인하기 위해 initWithStyle 방법에 NSLog 문을 삽입 시도 근래

이 완벽하게