1
我想將UItextField放入UITableViewCell中,但是我遇到了問題。文本字段不顯示。這是我的代碼: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方法被調用。可以有人幫助我嗎?
HAV您是否嘗試過在你的initWithStyle方法插入的NSLog語句,以確保它獲取調用?你是否在cellForRowAtIndexPath中設置textField文本屬性的值? – jonkroll 2012-03-24 07:48:24
是的,我用NSLog試過。看到我edtited的帖子。 – 2012-03-24 07:53:23
你可以顯示'self.textField'的屬性聲明嗎? – borrrden 2012-03-24 07:55:02