becomeFirstResponder not working in iOS 8

前端 未结 8 770
不知归路
不知归路 2020-12-09 03:55

I am using UITextField\'s method becomeFirstResponder to show the keyboard. This is working in iOS 7. But in iOS 8 this method doesn\'t show the keyboard.

 U         


        
8条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-09 04:30

    Swift 4 and iOS 11

    In my case, no mater what I tried, I was not able to set first responder until I tried this.

    func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
        if cell.isKind(of: YOURTABLEVIEWCELL.self) {
            if let yourCell = cell as? YOURTABLEVIEWCELL{
                yourCell.yourUiTextField.becomeFirstResponder()
            }
        }
    }
    

    Hope this helps someone stuck with the same problem.

提交回复
热议问题