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 메서드가 호출됩니다. 누군가 나를 도와 줄 수 있습니까?
작동합니다? cellForRowAtIndexPath에 textField의 text 속성 값을 설정하고 있습니까? – jonkroll
예 NSLog를 사용해 보았습니다. 내 edtited 게시물을 참조하십시오. –
'self.textField'에 대한 속성 선언을 보여줄 수 있습니까? – borrrden