如何修复'UITextFieldDidEndEditingReason'仅适用于iOS 10.0或更高版本

时间:2018-05-28 10:41:27

标签: ios swift uitextfielddelegate

我收到此错误

  

'UITextFieldDidEndEditingReason'仅适用于iOS 10.0或更高版本

代码

func textFieldDidEndEditing(_ textField: UITextField, reason: UITextFieldDidEndEditingReason) {
            if(reason == UITextFieldDidEndEditingReason.committed)
            {

            }
        }

我知道我可以使用下面的代码

func textFieldDidEndEditing(_ textField: UITextField) {

    }

但我的问题是我如何使用UITextFieldDidEndEditingReason与iOS 9的兼容性。我尝试了#available(iOS 10,*),但它似乎无法用于函数

2 个答案:

答案 0 :(得分:1)

未用作// this code looks awful, and does not work val r1 = for { barName <- barName() f <- insertFoo(barName) } yield e r1.flatMap { f => f.id match { case Some(id) => val r2 = for { _ <- insertChild1(id) _ <- insertChild2(id) _ <- insertChild3(id) _ <- insertChild4(id) } yield Unit r2 transform { case Failure(e) => // The compensation deleteFoo(id) Failure(e) case Success(v) => Success(e) } } } r1 。其if #available(iOS 10, *)

在您的代码中替换:

@available(iOS 10.0, *)

使用:

  func textFieldDidEndEditing(_ textField: UITextField, reason: UITextFieldDidEndEditingReason) {
        if(reason == UITextFieldDidEndEditingReason.committed)
        {

        }
    }

答案 1 :(得分:1)

您正在寻找@available

@available(iOS 10.0, *)
func textFieldDidEndEditing(_ textField: UITextField, reason: UITextFieldDidEndEditingReason) {
...
}

记录here