重新加载tableview或重新加载特定行或插入和删除时的Keyboardhide [英] Keyboardhide on reload tableview or on reload particular row or on insert and delete

查看:92
本文介绍了重新加载tableview或重新加载特定行或插入和删除时的Keyboardhide的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个tableview单元格,其中还有一个具有textfield的另一个tableview,并且如果我更改textfield的值,我需要重新加载表格视图或重新加载该特定行,但是在重新加载表格时它会隐藏键盘.任何将键盘保持原样的想法???

i have tableview cell in which there is another tableview in which i have textfield and if i change value of textfield, i need to reload table view or reload that that particular row but it hides the keyboard as table is reload. Any idea to keep the keyboard as it is ???

我尝试遵循stackoverflow建议,但不适用于我.

i have try following stackoverflow suggestions but it's not work for me.

在重新加载UITableView部分时保持UIKeyboard

也请尝试以下代码.

[self.tblADMEDesign beginUpdates];
[self.tblADMEDesign insertRowsAtIndexPaths:@[selectedIndexPath] withRowAnimation:UITableViewRowAnimationRight];
[self.tblADMEDesign deleteRowsAtIndexPaths:@[selectedIndexPath] withRowAnimation:UITableViewRowAnimationNone];
[self.tblADMEDesign endUpdates];

[self.tblADMEDesign beginUpdates];
[self.tblADMEDesign endUpdates];

[self.tblADMEDesign beginUpdates];
[self.tblADMEDesign reloadRowsAtIndexPaths:@[selectedIndexPath] withRowAnimation:UITableViewRowAnimationNone];
[self.tblADMEDesign endUpdates];

推荐答案

是在重新加载UITableView内容时保持键盘打开的最佳解决方案.

This is the best solution to keep the keyboard open while reload UITableView content.

如果它不适合您,那就不用担心.我有办法打开键盘.

If it is not worked for you then don't worry. I have a hack to open the keyboard as it.

请按照以下步骤操作,我相信它会为您工作.

Please follow the below steps, I am sure it will work for you.

  • 将一个虚拟UITextField放入您的视图controller(Storyboard)
  • 随意提供constraints(无关紧要)
  • 始终从情节提要中保留隐藏的假人UITextField.
  • 将隐藏的虚拟对象UITextFieldoutlet放入类文件.
  • 现在在reloadData()之前进行黑客攻击的时间只需致电txtDummy.becomeFirstResponder()
  • Take one dummy UITextField into your view controller(Storyboard)
  • Give constraints as you like(Doesn't matter)
  • Keep hidden dummy UITextField always from storyboard.
  • Take outlet of hidden dummy UITextField into class file.
  • Now time for the hack before reloadData() just call txtDummy.becomeFirstResponder()

请参阅下面针对已解决问题的代码.

Refer below code I have done to the resolved issue.

class ViewController: UIViewController,UITableViewDelegate,UITableViewDataSource {

      @IBOutlet weak var txtDummy: UITextField!
        @IBOutlet weak var tblView: UITableView!

        override func viewDidLoad() {
            super.viewDidLoad()
            tblView.register(UINib.init(nibName: "CustomTableViewCell", bundle: nil), forCellReuseIdentifier: "CustomTableViewCell")
        }

        func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
            return 10
        }

        func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
            let cell = tableView.dequeueReusableCell(withIdentifier: "CustomTableViewCell", for: indexPath) as! CustomTableViewCell
            cell.txtField?.text = "text"
            return cell
        }

        @IBAction func reloadtable(){
            txtDummy.becomeFirstResponder()
            tblView.reloadData()
            //Perform other operation after some delay
        }
    }

请参阅下面所附的演示应用程序源代码.如果需要任何进一步的帮助.

Refer below attached source code of the demo application. If any further help required.

源代码

如果适合您,请标记为接受.

Please mark as accepted if it will work for you.

这篇关于重新加载tableview或重新加载特定行或插入和删除时的Keyboardhide的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆