2014-05-17 31 views
0

我有一個頂部有一個表格並且底部有一個文本區域的視圖。有點像聊天。我設想當用戶在TextField中鍵入內容並按下發送按鈕(在屏幕截圖中未顯示)時,表格將隨該條目一起更新。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} 
+0

爲何選擇投票? – Anthony

回答

0

您在哪裏創建視圖?在自定義內UITableViewCell?如果是這樣,請在您的layoutSubviews方法中,確保不要撥打super,系統titleview和subtlte視圖將不會創建。

在這裏看到一個例子: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 

沿着這些行的東西應該工作。

+0

這兩個視圖(表視圖和uview)正在一個單獨的UIView中創建。所以他們都在UIView的保護傘下。我已經用'rmq.log:tree'的輸出更新了這個問題。我會看看你發佈的例子。謝謝 – Anthony

+0

我也遇到過這個,但不知道這是否能解決我的問題。 http://stackoverflow.com/questions/1247113/iphone-keyboard-covers-uitextfield – Anthony

相關問題