TextField未显示在顶部有表格而底部有文本字段的视图上

时间:2014-05-17 17:43:28

标签: ios rubymotion

我的视图顶部有一个表格,底部有一个文本字段。有点像聊天。我设想当用户在TextField中键入内容并按下发送按钮(屏幕截图中未显示)时,表格将使用该条目进行更新。

enter image description here

问题

我的问题是,当我点击TextField时,键盘会显示,但TextField不可见。如下面的屏幕截图所示。

enter image description here

这就是我制作这两种观点的方式:

@my_table = rmq(self.view).append(UITableView, :top_style).get
@bottom = rmq(self.view).append(UIView, :bottom_style).get
@bottom = rmq(:bottom_style)
@send = @bottom.append(UITextField, :send).get

样式表

  def top_style(st)
    st.frame = {t: 0, l: 0, w: screen_width, h: screen_height - 100}
    st.background_color = color.white
  end

  def bottom_style(st)
    st.frame = {t: screen_height-100, l: 0, w: screen_width, h: screen_height}
    st.background_color = color.battleship_gray
  end

  def send(st)
    st.frame = {l: 3, t: 5, w: 220, h: 30}
    st.background_color = color.white
    st.view.font = font.small
    st.layer.cornerRadius = 5
    st.view.placeholder = "say something..."
  end

更新

从RMQ日志输出

─── UIView  282653120  {l: 0, t: 64, w: 320, h: 504}
    ├─── UITableView  ( top_style )  264785408  {l: 0, t: 0, w: 320, h: 468}
    │    ├─── UITableViewWrapperView  282624240  {l: 0, t: 0, w: 320, h: 468}
    │    │    ├─── NotesCell  ( note_cell )  282682640  {l: 0, t: 60, w: 320, h: 30}
    │    │    │    ├─── UITableViewCellScrollV  282585904  {l: 0, t: 0, w: 320, h: 30}
    │    │    │    │    ├─── UITableViewCellContent  282688128  {l: 0, t: 0, w: 320, h: 30}
    │    │    │    │    │    ├─── UILabel  ( cell_label )  282583168  {l: 15, t: 0, w: 290, h: 30}
    │    │    ├─── NotesCell  ( note_cell )  282696944  {l: 0, t: 30, w: 320, h: 30}
    │    │    │    ├─── UITableViewCellScrollV  282690432  {l: 0, t: 0, w: 320, h: 30}
    │    │    │    │    ├─── UITableViewCellContent  282617184  {l: 0, t: 0, w: 320, h: 30}
    │    │    │    │    │    ├─── UILabel  ( cell_label )  282578944  {l: 15, t: 0, w: 290, h: 30}
    │    │    ├─── NotesCell  ( note_cell )  282671168  {l: 0, t: 0, w: 320, h: 30}
    │    │    │    ├─── UITableViewCellScrollV  282723568  {l: 0, t: 0, w: 320, h: 30}
    │    │    │    │    ├─── UITableViewCellContent  282709936  {l: 0, t: 0, w: 320, h: 30}
    │    │    │    │    │    ├─── UILabel  ( cell_label )  282653440  {l: 15, t: 0, w: 290, h: 30}
    │    ├─── UIImageView  282715328  {l: 316.5, t: 461, w: 3.5, h: 7}
    │    ├─── UIImageView  282714752  {l: 313, t: 464.5, w: 7, h: 3.5}
    ├─── UIView  ( bottom_style )  282440352  {l: 0, t: 468, w: 320, h: 568}
    │    ├─── UITextField  ( send )  282618928  {l: 3, t: 5, w: 220, h: 30}
    │    │    ├─── UITextFieldLabel  282587568  {l: 0, t: 0, w: 220, h: 29}

1 个答案:

答案 0 :(得分:0)

您在哪里创建视图?在自定义UITableViewCell内?如果是这样,请在layoutSubviews方法中,确保不要致电super,系统标题视图和子视图视图也不会被创建。

请点击此处查看示例:https://github.com/MohawkApps/aloft/blob/master/app/views/wind_cell.rb#L18

编辑...以前没有完全理解这个问题。

在显示和隐藏键盘时,您似乎必须手动重新定位底部视图。尝试这样的事情:

def create_stuff
  @my_table = rmq(self.view).append(UITableView, :top_style).get
  @bottom = rmq(self.view).append(UIView, :bottom_style).get
  @bottom = rmq(:bottom_style)
  @send = @bottom.append(UITextField, :send).get
  @send.get.delegate = self # This is crucial for the rest to work
end

def textFieldDidBeginEditing(textField)
  rmq(@bottom).animate(
    duration: 0.3,
    animations: lambda{|q|
      q.move top: keyboard_height # Animate it somewhere
    }
  )
end

def textFieldDidEndEditing(textField)
  rmq(@bottom).animate(
    duration: 0.3,
    animations: lambda{|q|
      q.move top: -keyboard_height # Animate it somewhere
    }
  )
end

这些方面应该有所作为。