Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xcode/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何让用户在swift中的xib单元格内的文本字段中输入文本_Swift_Xcode_Uitextfield_Iqkeyboardmanager - Fatal编程技术网

如何让用户在swift中的xib单元格内的文本字段中输入文本

如何让用户在swift中的xib单元格内的文本字段中输入文本,swift,xcode,uitextfield,iqkeyboardmanager,Swift,Xcode,Uitextfield,Iqkeyboardmanager,我创建了一个包含两个文本字段的xib单元格。文本字段作为IBOutlet连接到xib swift文件。xib单元在视图控制器上注册为Nib。当我在模拟器上运行应用程序时,我无法显示键盘。其次,文本字段根本不可编辑,也就是说光标甚至不显示。我想在这方面得到帮助,因为我已经尝试使用标签,同样的事情也会发生。我只是不知道如何修复这个。我没有在构建时出错。我已经从cocoapods安装了IQKeyboardManager。提前谢谢 代码如下: import UIKit class Dictionary

我创建了一个包含两个文本字段的xib单元格。文本字段作为IBOutlet连接到xib swift文件。xib单元在视图控制器上注册为Nib。当我在模拟器上运行应用程序时,我无法显示键盘。其次,文本字段根本不可编辑,也就是说光标甚至不显示。我想在这方面得到帮助,因为我已经尝试使用标签,同样的事情也会发生。我只是不知道如何修复这个。我没有在构建时出错。我已经从cocoapods安装了IQKeyboardManager。提前谢谢

代码如下:

import UIKit

class DictionaryCell: UITableViewCell {

    @IBOutlet weak var DictBubble: UIView!
    @IBOutlet weak var DictSymbolTextfield: UITextField!
    @IBOutlet weak var SymbolMeaningTextfield: UITextView!
    
    
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }
    
}
以下是视图控制器代码:

import UIKit
import Firebase

class PersonalDreamDictionaryViewController: UIViewController, UITextViewDelegate  {
    
    
    
    @IBOutlet weak var tableView: UITableView!
    @IBOutlet weak var dictionaryTextfield: UITextField!
    
    
    let db = Firestore.firestore()
    
    var dreamDictionary: [DreamDictionary] = []
    
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
        tableView.dataSource = self
        tableView.delegate   = self
        title = K.Dictionary.appName
        
        
        tableView.register(UINib(nibName: K.Dictionary.cellNibName, bundle: nil), forCellReuseIdentifier: 
        K.Dictionary.cellIdentifier)
        
        loadDictionaryList()
        
    }
    
    func loadDictionaryList() {
        
        db.collection(K.Fstore1.collectionName)
            .order(by: K.Fstore1.date)
            .addSnapshotListener{ (QuerySnapshot, error) in
                
                self.dreamDictionary = []
                
                if let e = error {
                    print("There was an issue retrieving data from Firestore. \(e)")
                } else {
                    if let snapshotDocuments = QuerySnapshot?.documents {
                        for doc in snapshotDocuments {
                            //print(doc.data())
                            let data = doc.data()
                            if let symbolRetrieved = data[K.Fstore1.symbol] as? String, let meaningRetrieved = data[K.Fstore1.meaning] as? String {
                                let newDictList = DreamDictionary(mysymbol: symbolRetrieved, mymeaning: meaningRetrieved)
                                self.dreamDictionary.append(newDictList)
                                
                                DispatchQueue.main.async {
                                    self.tableView.reloadData()
                                }
                                
                            }
                        }
                    }
                }
                
        }
    }
}


extension PersonalDreamDictionaryViewController: UITableViewDataSource {
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return dreamDictionary.count
        
    }
    
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        
        let dictCell = tableView.dequeueReusableCell(withIdentifier: K.Dictionary.cellIdentifier, for: indexPath)
            as! DictionaryCell

        
        if let symbolInput = dictCell.DictSymbolTextfield.text, let meaningInput = dictCell.SymbolMeaningTextfield.text { db.collection(K.Fstore1.collectionName).addDocument(data: [
            K.Fstore1.symbol: symbolInput,
            K.Fstore1.meaning: meaningInput,
            K.Fstore1.date: Date().timeIntervalSince1970
            
        ]) { (error) in
            if let e = error {
                print("There was an issue saving data to firesore, \(e)")
            } else {
                print("Successfully saved data.")
            }
            }
            
        }
        return dictCell           
    }

}



extension PersonalDreamDictionaryViewController: UITableViewDelegate {
    func tableView(_ tableView: UITableView, willBeginEditingRowAt indexPath: IndexPath) {
        print(indexPath.row)
        
    }
}

为了Clarify,我需要控制键盘。当我按下回车键时,我希望键盘被关闭。这很有挑战性,因为文本字段不在视图控制器上,而是在XIB上。任何帮助都将不胜感激。谢谢clairfy,我需要控制键盘。当我按下回车键时,我希望键盘被关闭。这很有挑战性,因为文本字段不在视图控制器上,而是在XIB上。任何帮助都将不胜感激。谢谢