现在我有一个验证功能来检查:
if let descText = myTextVIEw.text { if descText.isEmpty { descErrorLabel.isHIDden = false } else { descErrorLabel.isHIDden = true }}
这足以阻止用户发送空文本视图,或者我也必须检查空格,例如:
stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceAndNewlineCharacterSet()).isEmpty解决方法 你可以把它全部卷成这样的东西……
func valIDate(textVIEw textVIEw: UITextVIEw) -> Bool { guard let text = textVIEw.text,!text.trimmingCharacters(in: CharacterSet.whitespacesAndNewlines).isEmpty else { // this will be reached if the text is nil (unlikely) // or if the text only contains white spaces // or no text at all return false } return true}
然后你可以验证任何UITextVIEw像……
if valIDate(textVIEw: textVIEw) { // do something} else { // do something else}总结
以上是内存溢出为你收集整理的ios – 快速检查textview是否为空全部内容,希望文章能够帮你解决ios – 快速检查textview是否为空所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)