iPhone 应用程序:
- 我有一个带有 3 个文本字段的屏幕,用于输入姓名、电子邮件和位置。
- 我使用了 2 个部分的分组表视图。
- 在 tat 第一部分有三个单元格..每个单元格都有一个标签 na 文本字段..例如:名为名称的标签和一个用于输入名称的文本框.. 明智地我也有它用于电子邮件和位置..
已将界面中的 nameTextField、emailTextField、locationTextField 声明为变量而不是属性。所以请告诉我如何在这里关闭键盘
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
CommonTableViewCell* cell = [[CommonTableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@""];
cell.textLabel.backgroundColor = [UIColor clearColor];
cell.textLabel.textColor = [UIColor blackColor];
cell.textLabel.highlightedTextColor = [UIColor whiteColor];
cell.textLabel.font = [UIFont fontWithName:@"Arial" size:14];//
cell.textLabel.font = [UIFont boldSystemFontOfSize:14];
//cell.image = [UIImage imageNamed:@"resources_on.png"];
cell.textLabel.frame = CGRectMake(TABLE_ROW_HEIGHT + 10, 5, self.view.frame.size.width , 25);
if (indexPath.section == 0) {
if (indexPath.row == 0) {
cell.textLabel.text = @"Username";
nameTextField = [[UITextField alloc] initWithFrame:CGRectMake(140, 18, 300, 20)];
[nameTextField setBackgroundColor:[UIColor clearColor]];
[nameTextField setFont:[UIFont fontWithName:@"Arial" size:14]];
nameTextField.placeholder = @"Enter anonymous name";
[nameTextField setKeyboardType: UIKeyboardTypeNamePhonePad];
[cell addSubview:nameTextField];
[nameTextField release];
}else if (indexPath.row == 1) {
cell.textLabel.text = @"Email";
emailTextField = [[UITextField alloc] initWithFrame:CGRectMake(140, 18, 300, 20)];
[emailTextField setBackgroundColor:[UIColor clearColor]];
[emailTextField setFont:[UIFont fontWithName:@"Arial" size:14]];
emailTextField.placeholder = @"example@me.com";
[emailTextField setKeyboardType:UIKeyboardTypeEmailAddress];
[cell addSubview:emailTextField];
[emailTextField release];
}else if (indexPath.row == 2) {
cell.textLabel.text = @"Location";
locationTextField = [[UITextField alloc] initWithFrame:CGRectMake(140, 18, 300, 20)];
[locationTextField setBackgroundColor:[UIColor clearColor]];
[locationTextField setFont:[UIFont fontWithName:@"Arial" size:14]];
locationTextField.placeholder = @"Fetch";
[cell addSubview:locationTextField];
[locationTextField release];
}else if (indexPath.row == 3) {
cell.textLabel.text = @"Terms of Use";
cell.thumbnailView.image = [UIImage imageNamed:@"compensation_on.png"];
}else if (indexPath.row == 4) {
cell.textLabel.text = @"Privacy Policy";
cell.thumbnailView.image = [UIImage imageNamed:@"compensation_on.png"];
}else {
}
} else if (indexPath.section == 1) {
if (indexPath.row == 0) {
cell.textLabel.text = @"Terms of Use";
cell.thumbnailView.image = [UIImage imageNamed:@"compensation_on.png"];
}else if (indexPath.row == 1) {
cell.textLabel.text = @"Privacy Policy";
cell.thumbnailView.image = [UIImage imageNamed:@"compensation_on.png"];
}else {
}
}
return cell;
}
这对我不起作用..
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
[textField resignFirstResponder];
return YES;
}