自定义表格视图单元格中的UITextField不再显示键盘,iOS 7 [英] UITextField in custom table view cell no longer brings up keyboard, iOS 7

查看:143
本文介绍了自定义表格视图单元格中的UITextField不再显示键盘,iOS 7的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个为iOS 5构建的应用程序,我正在尝试直接升级到iOS 7,所以这也可能是iOS 6的一个问题。

I have an app built for iOS 5 that I'm trying to upgrade straight to iOS 7, so this also maybe an issue with iOS 6.

我们有自定义表视图单元格(从UITableCellView派生的类)中的UITextField,但点击它不再在模拟器中调出键盘。一切都已启用,并且已启用用户交互已启用。

We have a UITextField inside a custom table view cell (class derived from UITableCellView), but tapping on it no longer brings up the keyboard in the simulator. Everything is enabled, and User Interaction Enabled is checked.

它曾在iOS 5中正常工作。

It used to work fine in iOS 5.

我不确定要包含哪些代码,但是这里是创建单元格的代码... LoginRegisterTableViewCell只有一个'fieldLabel'(UILabel)和'userText'(UITextField):

I'm not sure what code to include, but here's the code that creates the cell... the LoginRegisterTableViewCell just has a 'fieldLabel' (UILabel) and 'userText' (UITextField):

    // Login area
    static NSString * reuseIdentifier = @"LoginRegisterTableViewCell";

    LoginRegisterTableViewCell * cell = (LoginRegisterTableViewCell *)[tableView dequeueReusableCellWithIdentifier:reuseIdentifier];
    if(cell == nil)
    {
        // The official Apple way of loading TableViewCell nibs
        // http://www.nomadplanet.fr/2011/01/custom-uitableviewcells-loaded-from-xib-howto-debug/
        [[NSBundle mainBundle] loadNibNamed:@"LoginRegisterTableViewCell" owner:self options:nil];
        cell = formFieldCell;
        self.formFieldCell = nil;
    }

    cell.delegate = self;
    cell.userText.tag = [indexPath row];

如果我调用[userText becomeFirstResponder,我可以让键盘出现当选择表格单元格时,这似乎是一种解决方法而不是正确的方法。

I can get the keyboard to come up if I call [userText becomeFirstResponder] when the table cell is selected, but this seems like a workaround as opposed to the correct way.

推荐答案

尝试使用此代码表视图数据源: cellForRowAtIndexPath

Try this code with the table view data source: cellForRowAtIndexPath

    NSString *cellReuseIdentifier = @"CellIdentifier";
    UINib *nib = [UINib nibWithNibName:@"CustomTableViewCell" bundle:nil];
   [_myTableView registerNib:nib forCellReuseIdentifier:cellReuseIdentifier];

    CustomTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:cellReuseIdentifier];
    if (!cell)
    {
        cell = [[CustomTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellReuseIdentifier];
    }

    return cell;

对我来说,使用xib创建的自定义单元格如图所示

It is working for me with the custom cell created with the xib as shown in the image

注意:标记同时创建XIB文件。

Note: Mark Also create XIB file.

并提供一个单元重用标识符,如

And give a cell reuse identifier like

这对我来说非常适用于示例应用程序而没有键盘问题。

This is working for me well for the sample application with no issue with the keyboard.

这篇关于自定义表格视图单元格中的UITextField不再显示键盘,iOS 7的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆