0

This is an unconventional setup and I appreciate that but I have added a UITableViewController as a child view controller in a UITableViewCell of another UITableView. Wow, yes. It's a complex view and it is being reused in multiple places, the code is clean and it works 98% so I'm reasonably happy.

The problem is when one of the textfields in my Franken-TableViewController becomes first responder. Because the controller doesn't know where it is, or the fact that it is in a tableview cell the tableview scrolls to the wrong offset. I obviously want the auto scrolling behaviour provided by the UITableViewController but I realise I will have to assist it figuring out where to scroll to.

I'm not sure what parameters the UITableViewController is looking at to determine where to scroll to. This article is discussing a very similar problem and also the fact that the content is only evaluated a single subview deep. Extra Space When Embedding Table Views

Suggestions how I can get around this without refactoring away using UITableViewController?

dantastic
  • 134
  • 1
  • 10
  • I understand you want to use a `UITableViewController` but what are you getting out of it that you can't just do with a `UIViewController`? – cnotethegr8 Jul 09 '18 at 17:03
  • https://stackoverflow.com/questions/33766993/stop-a-uitableview-from-automatically-scrolling – cnotethegr8 Jul 09 '18 at 17:06
  • i would suggest to try to set different values for `tableview.contenInset` when the textfield becomes first responder ( eg. in `textFieldShouldBeginEditing:`) – bbjay Jul 09 '18 at 17:10

1 Answers1

0

The answer is to not use a UITableViewController. Yes, the UITableViewController will give you keyboard avoiding text fields for free but as we all know, there's no such thing as a free lunch.

There are ways you can stop the animations for taking place and recalculating yourself but really, at the end of the day it's just a dodgy hack.

I ended up refactoring my UITableViewControllers into UIViewControllers with IBOutlets to the tableViews. You just need to add some keyboard avoiding code yourself, which you probably already have in your app.

dantastic
  • 134
  • 1
  • 10