angerman
angerman

Reputation: 4149

UITableViewController -- event when view changes size?

The UITableViewController changes it's tableview's when the keyboard appears. I'd like the cells to stay where the are; the default behavior is that the view is simply shrunk and the top cell stays where it is. I'd rather have the bottom cell to stay at the visible button.

There are two approaches I can think of:

EDIT: I seem not to have been clear. The UITableView is actually resized. (Seems to be a feature of the UITableViewController. The problem I'm having is the behavior of the UIScrollView of the UITableView that contains the UITableViewCells. Listening for the UIKeyboardDidShow and similar events just to reposition the scroll position feels like shooting sparrows with cannons.

Upvotes: 1

Views: 457

Answers (2)

d.ennis
d.ennis

Reputation: 3455

You can control on how the tableview will be resized and/or scrolled the cells in the UIKeyboardDidShowNotification. Therefore you first have to make your UITableViewController observing the following two Notifications (not sure if this is necessary for TableViewControllers) :

 [[NSNotificationCenter defaultCenter] addObserver:self
        selector:@selector(keyboardWasShown:)
        name:UIKeyboardDidShowNotification object:nil];

 [[NSNotificationCenter defaultCenter] addObserver:self
         selector:@selector(keyboardWillBeHidden:)
         name:UIKeyboardWillHideNotification object:nil];

You could do that in your viewDidLoad Method. Then you have to write some code to do what you want. As a starting point I recommend you to use the code snippets out of Moving Content That Is Located Under the Keyboard from the Apple "Text, Web, and Editing Programming Guide for iOS".

Upvotes: 0

Jonah
Jonah

Reputation: 17958

Yes. Stop using UITableViewController if it doesn't provide the behaviors you want. Instead just create a UIViewController subclass with a UITableView property, listen for the keyboard notifications, and respond however you like; adding insets to the table view and scrolling to keep cells visible as desired.

Upvotes: 1

Related Questions