Ich möchte UItextField in UITableViewCell platzieren, aber ich habe ein Problem. Textfeld wird nicht angezeigt. Das ist mein Code:UITextField in UITableViewCell
-(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;
}
Ich Test und InitWithStyle-Methode heißt. Kann jemand mir helfen?
Hav Sie eine NSLog-Anweisung in der initWithStyle Methode Einfügen versucht es, um sicherzustellen, wird immer genannt? Setzen Sie den Wert der Text-Eigenschaft Ihres textFields in cellForRowAtIndexPath? – jonkroll
Ja, ich habe es mit NSLog versucht. Siehe meine editierte Post. –
Können Sie die Eigenschaftsdeklaration für 'self.textField' anzeigen? – borrrden