【问题标题】:how to manage scrolling of table view containing text fields如何管理包含文本字段的表格视图的滚动
【发布时间】:2011-12-22 19:46:42
【问题描述】:

当我尝试滚动和编辑 UITableView 底部的单元格时,我无法将单元格正确定位在键盘上方。实际上键盘隐藏了一半的表格视图。

我还为我的单元格单独创建了一个自定义单元格类。因此文本字段委托仅在该类上可用。我不能在我的 table biew 的视图控制器中使用它们

我已经看到很多关于更改视图大小等的答案......但到目前为止,它们都没有很好地工作。

谁能帮我写一段代码

【问题讨论】:

    标签: objective-c uitableview


    【解决方案1】:

    现在有一种更简单的方法(不知道它已经可用了多久):如果您要覆盖 viewWillAppear,请确保在顶部包含

    [super viewWillAppear:animated];
    

    我已经准备好开始监听键盘事件以及设置和删除约束,仅这一行就消除了所有其他代码。

    【讨论】:

      【解决方案2】:

      你想调整 UITableView 的 scrollView 组件。设置您的视图控制器以响应键盘通知。像这样:

      - (void)viewWillAppear:(BOOL)animated 
      {
          [super viewWillAppear:animated];
          [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
          [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
      
      }
      
      
      - (void)viewWillDisappear:(BOOL)animated 
      {
          [super viewWillDisappear:animated];
          [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil];
          [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil];
      }
      

      然后创建一个keyboardWillShow: 函数并通过操作tableView.scrollview.contentOffset 来调整tableview(它可能是tableView.contentOffset 我不在xcode 附近)。确保您使用keyboardWillHide 函数将其调整回0,0。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-07-16
        • 1970-01-01
        • 2013-05-14
        • 1970-01-01
        相关资源
        最近更新 更多