如何在表格单元格中创建UITextField成为第一响应者?

can*_*boy 5 iphone objective-c uitextfield ios

如果我有一系列表格单元格,每个表格单元格都有一个文本字段,我将如何使特定的文本字段成为第一个响应者?

Nil*_*ani 6

// Customize the appearance of table view cells.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) 
{
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    UITextField *textField = [[UitextField alloc] init];
 ...
     textField.delegate = self;
     textField.tag = indexPath.row;
     [cell addSubView:textField];
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
    [textField resignFirstResponder];
    return YES;
}
Run Code Online (Sandbox Code Playgroud)

我希望这可以帮助你......