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
}
}
シミュレータモードでテストしようとしていますか? –
yes on ipad 9.7 landscape ios 10 –
シミュレータの設定でキーボードが無効になっていないことを確認してください –