简体   繁体   中英

Keyboard doesn't appear when first click on UITableViewCell in grouped UITableView

I'm developing an application in iOS6 and i'm using XCode 4.5.2.

I've a UITableView which style is grouped . Every single cell has a UITextField which size is exactly equal to UITableViewCell size. To create UITextField , i'm using this piece of code.

  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 ];

And i'm adding this UITextField to cell as a subview. The problem is that sometimes, when i clicked on the cell, keyboard is supposed to show up. But,here is the screenshot when i clicked on any of cell. 单击单元格时的屏幕截图

It means that when i add UITextField to a cell , it has no effect. Because, it's the normal behaviour of the UITableView . The weird issue is that when i clicked on one more times, the keyboard appears, and it's working as it should. But, there is still blue color on the each cell, i can't get it destroyed. Here is the second screenshot. 第二次截图

And,also it doesn't happen always, so i'm not able to detect what causes this unexpected behaviour.

Do you guys have any idea how can i resolve this problem and what causes it ?

Thank you.

我认为您只需要将tableView.allowsSelection设置为FALSE即可。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM