【问题标题】:Keyboard not showing for UITextFieldUITextField 没有显示键盘
【发布时间】:2015-10-06 16:17:20
【问题描述】:

我有一个包含UICollectionView 的 UIView,其中包含自定义单元格。这些自定义单元格包含 UILabelUITextField。自定义单元类和UICollectionView 委托方法之一的代码是:

class DurationDayCells: UICollectionViewCell {
    @IBOutlet weak var dayLabel: UILabel!

    @IBOutlet weak var dayHourText: UITextField!
}

func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
    return daysSet.count
}

func collectionView(collectionView: UICollectionView!,layout collectionViewLayout: UICollectionViewLayout!,sizeForItemAtIndexPath indexPath: NSIndexPath!) -> CGSize {

    return CGSize(width: (self.durationCollectionView.frame.width/CGFloat(daysSet.count)), height:
        self.durationCollectionView.frame.height)

}

如您所见,这些单元格是根据daysSet 的大小动态创建和调整大小的。问题是当我点击单元格中的一个文本字段时,键盘不会弹出(粉红色/红色视图是所说的UIView):

我还有一个后续问题,当我确实设法使键盘显示时(不知何故),它完全阻止了粉红色/红色 UIView,有没有办法在文本时将整个 UIView 向上移动字段被选中所以键盘不会阻止它?

【问题讨论】:

    标签: ios swift uitextfield uikeyboard


    【解决方案1】:

    关于键盘未显示,模拟器可能设置为链接您计算机的键盘。来自Xcode 6: Keyboard does not show up in simulator

    iOS 模拟器 -> 硬件 -> 键盘

    取消选中“连接硬件键盘”

    为了让您的内容在显示键盘时自动向上滚动,CocoaPod IQKeyboard 专为此 https://github.com/hackiftekhar/IQKeyboardManager 构建。

    如果您不知道 CocoaPods 是什么,我强烈建议您通过https://cocoapods.org/查看它们

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-03-02
      • 1970-01-01
      • 2011-04-05
      • 1970-01-01
      • 1970-01-01
      • 2012-02-05
      • 1970-01-01
      相关资源
      最近更新 更多