我正在 iOS6 中开发一个应用程序,我正在使用 XCode 4.5.2。
我有一个UITableView样式是grouped
. 每个单元格都有一个UITextField,其大小与UITableViewCell大小完全相同。要创建UITextField,我正在使用这段代码。
UITextField *txtField = [[UITextField alloc]initWithFrame:CGRectMake(20, 10, 320, 44)];
txtField.autocorrectionType = UITextAutocorrectionTypeNo ;
txtField.opaque = 1.0;
txtField.contentMode = UIViewContentModeCenter;
if(indexPath.row == 0)
txtField.placeholder = @"Name";
else if(indexPath.row == 1)
txtField.placeholder = @"Email";
if(indexPath.section == 2)
txtField.placeholder = @"Write here...";
[cell addSubview:txtField ];
我正在将此UITextField添加为cell
子视图。问题是有时,当我点击单元格时,键盘应该会出现。但是,这是我单击任何单元格时的屏幕截图。
这意味着当我将UITextField添加到 acell
时,它没有效果。因为,这是UITableView的正常行为。奇怪的问题是,当我再点击一次时,键盘出现了,它正在正常工作。但是,每个单元格上仍然有蓝色,我无法将其破坏。这是第二个屏幕截图。
而且,它并不总是发生,所以我无法检测出导致这种意外行为的原因。
你们知道我该如何解决这个问题以及导致它的原因吗?
谢谢你。