开发者

Need help with UISearchBar and NSString

开发者 https://www.devze.com 2022-12-29 02:15 出处:网络
I would like to make an if command that checks the value of my UISearchBar in that way if the value of the UISearchBar is equals to \" \" or multiple spaces without words and chars, an alert will popu

I would like to make an if command that checks the value of my UISearchBar in that way if the value of the UISearchBar is equals to " " or multiple spaces without words and chars, an alert will popup. Well, I don't need help with the creation of the alert but I do need help with the if command and th开发者_如何转开发e spaces. I know how to do it with multiple "if" command but I want with only 1.

Thanks!


If I'm understanding the question correctly, you want to check for whitespace.

if ([[theSearchBarText stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] length] == 0){
    // Search string is empty
}
0

精彩评论

暂无评论...
验证码 换一张
取 消