I had the same problem, I had a UITableView in the smaller container view, and when I selected the UITextField in the tableView, it would automatically scroll to an undesirable position. This is the default behavior for a UITableView and there is no way to disable it.
Instead, I changed this subView controller to a subclass of UIViewController instead of UITableViewController. ie for my TransportViewController.h that controls tableView:
@interface TransportViewController : UITableViewController <UITextFieldDelegate>
become:
@interface TransportViewController : UIViewController <UITextFieldDelegate, UITableViewDataSource, UITableViewDelegate>
By setting the class as the UIViewController class, automatic scrolling of table cells will not occur.
Now that you are not subclassing the UITableViewController, you must manually set the tableView property to indicate the appropriate type of table. You can link this in IB, which will give you something like:
@property (strong, nonatomic) IBOutlet UITableView *tableView;
Finally, you will also need to set this newly assigned tableView property as the delegate and table data source. You can do this in the 'viewDidLoad' method as follows:
- (void)viewDidLoad { [super viewDidLoad]; _tableView.dataSource = self; _tableView.delegate = self; }
This will stop the automatic scrolling that is inherent in the UITableViewController when selecting a UITextField. Then you need to implement any necessary UITableViewDataSource methods and process your own auto scroll methods.
Tys
source share