UITableViewController automaticly manages textfield editing: scrolling to editable content, changing insets to display textfield and keyboard on screen simultaneously without keyboard overlapping. It's very cool feature because i don't need to write a lot of code to calculate new insets, scroll to content, check if deviceOrientation changed or keyboard hidden and so on.
But that feature fails when we are using SplitViewController, after we adding to root that controller automatic management of textfield is working only on Pad-oriented screens. I think that's Apple's bug, but maybe it's my mistake and i'm doing something wrong? I've checked that SplitViewController -> Navigation Controller -> UITableViewController hierarchy is correct in Apple's HID.
I've written simple application for that question so you can see that bug if you want, how can I fix it?
Link to simple, fresh XCode project with that bug: https://www.dropbox.com/s/o315awgonzeskeo/TableEditing.zip?dl=0
Semi-solution: remove SplitViewController if device is iPhone. Everything is working ok on iPad, but not working on iPhone, so we may try that:
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let rootController = storyboard.instantiateViewControllerWithIdentifier("navigation") as! UINavigationController
if UIDevice.currentDevice().userInterfaceIdiom != .Pad {
// setting non-split rootView if device is iPhone
self.window!.rootViewController = rootController
}
}
But there is problem — we are loosing SplitViewController on iPhone 6 Plus (i checked, on iPhone 6 Plus on portrait orientation keyboard still overlaps, on landscape all is ok). So it's not the solution.
The best way to handle such situations is to manually control your UITableView
and move it above keyboard. I've create small class for it, it increases and decreases size of your constraint (it maybe be constraint from UITableView
to bottom of a view) if keyboard appears/disappears.