开发者

UITableViewController -- event when view changes size?

开发者 https://www.devze.com 2023-04-13 07:48 出处:网络
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

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:

  • Can I tell the tableview to shrink from the top instead of shrinking from the bottom?
  • Can I intercept the change in size? In that case I could call the scroll method to scroll to the bottom.

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 f开发者_StackOverflowor the UIKeyboardDidShow and similar events just to reposition the scroll position feels like shooting sparrows with cannons.


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.


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".

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号