// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *placeholder;
static NSString *CellIdentifier = @"Editable";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
}
//ここでセルに追加するテキストフィールドを作成
//initWithFrameでCGrectMakeを使っているのが重要!
//(綺麗に収まるなら[[textfield superview] frame]でも良い)
UITextField *textfield = [[UITextField alloc] initWithFrame:CGRectMake(20, 10, 280, 30)];
[textfield retain];
switch (indexPath.row) {
case 0:
placeholder = @"User";
[[NSNotificationCenter defaultCenter]
addObserver:self selector:@selector(exitTextField:) name:@"UITextFieldTextDidEndEditingNotification" object:textfield];
break;
case 1:
placeholder = @"Password [Optional]";
textfield.secureTextEntry = YES;
break;
default:
break;
}
textfield.returnKeyType = UIReturnKeyDone;
textfield.placeholder = placeholder;
//そしてcellにaddSubview
[cell addSubview:textfield];
// Set up the cell...
return cell;
}