0

I have a UIView that contains a UICollectionView, which contains custom cells. These custom cells contain a UILabel and a UITextField. The code for the custom cell class and the UICollectionView one of the delegate methods is:

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)

}

So as you can see, these cells are dynamically created and sized according to the size of daysSet. The problem is when I tap one of the text fields in the cells the keyboard does not pop up (the pink/red view is the said UIView):

screenshot1

I also have a follow up question for when I did manage to make the keyboard show (somehow), it blocked the pink/red UIView completely, is there a way to move the whole UIView up when a text field is selected so the keyboard does not block it?

Rishil Patel
  • 1,977
  • 3
  • 14
  • 30
Liumx31
  • 1,190
  • 1
  • 16
  • 33

1 Answers1

12

About the keyboard not showing up, the simulator might be set to link your computer's keyboard. From Xcode 6: Keyboard does not show up in simulator

iOS Simulator -> Hardware -> Keyboard

Uncheck "Connect Hardware Keyboard"

For getting an easy way to have your content scroll up automatically when a keyboard shows, the CocoaPod IQKeyboard is built just for this https://github.com/hackiftekhar/IQKeyboardManager

If you don't know what CocoaPods are, I strongly suggest checking them out at https://cocoapods.org/

Community
  • 1
  • 1
David Cao
  • 525
  • 3
  • 11