2017-03-14 5 views
2

各セルに複数のテキストフィールドがあるテーブルビューを作成しようとしています。すぐにテーブルビュー内でテキストフィールドを機能させる方法

テキストフィールドで単純なリストを作成することはできましたが、テキストフィールドを押すと何も起こりません。キーボードはポップアップしないで、他のビューでイベントがキャプチャされているように感じます。

ユーザーインタラクションが有効に設定されていることを確認しました。 私はあなたがコメントに見えるように、ビューを前面にプッシュしようとしました。

私には何が欠けていますか?

私のテーブルはMainTableと呼ばれ、 私InputviewCellがtxtFieldTemp

import Foundation 
import UIKit 

class PrioritiesGridViewController: UIViewController,UITableViewDataSource, UITableViewDelegate, UITextFieldDelegate 
{ 

@IBOutlet var mainTable: UITableView! 

override func viewDidLoad() { 
    super.viewDidLoad() 

    mainTable.delegate = self 
    mainTable.dataSource = self 
    //mainTable.allowsSelection = false 
} 

let data = AuxClass() 

func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { 
    return 62 
} 

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 
    return data.everything().count 
} 

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 
    let cell = Bundle.main.loadNibNamed("InputTextViewCell", owner: self, options: nil)?.first as! InputTextViewCell 

    cell.selectionStyle = UITableViewCellSelectionStyle.none 
    cell.txtFieldTemp.delegate = self 
    cell.txtFieldTemp.text = "test" 

    cell.txtFieldTemp.allowsEditingTextAttributes = true 
    //self.view.bringSubview(toFront: cell.txtFieldTemp) 

    return cell; 
} 

override var canBecomeFirstResponder: Bool { return true} 

func textFieldShouldBeginEditing(_ textField: UITextField) -> Bool { 
    return true 
} 


func numberOfSections(in tableView: UITableView) -> Int { 
    return 1; 
} 

func textFieldDidBeginEditing(_ textField: UITextField) { 
    self.isEditing = true 

} 


} 

class AuxClass 
{ 
var objectsArray = [Objects(
    field1: "teste", 
    field2: 3), 
    Objects(
     field1: "teste1", 
     field2: 4) 
] 

struct Objects { 
    var field1: String! 
    var field2: Int 
} 


func everything() -> [Objects] 
{ 
    return objectsArray 
} 
} 
+0

シミュレータモードでテストしようとしていますか? –

+0

yes on ipad 9.7 landscape ios 10 –

+0

シミュレータの設定でキーボードが無効になっていないことを確認してください –

答えて

0

という名前のテキストフィールドを持つだけで、正常細胞(XIB)ですがcell.txtFieldTemp.becomeFirstResponder()で試してみてください。 apple documentationを見ると、最初のレスポンダーになると思います。

関連する問題