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 the 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
}
Related
Hi I'm trying to put an arrow into a UILabel's text but it is not working. I'm trying the following code
NSString *labeltext = #"➜";
label.text = labeltext;
But that makes the app crash!
(if you go to the edit menu and go to special characters then it is the 10th rightwards arrow)
.
Thanks for your help in advance
Code should be working by just writing the special character directly in the code as written in the question also
label.text=#"➜";
but in case it is not working then there are alternative ways to print the special characters in IOS, You need to use Unicode character of this sign , check out this page codes and after getting the code just do like as follows
UniChar ucode = 0x2794;
NSString *codeString = [NSString stringWithCharacters:&ucode length:1];
[label setText:codeString];
OR Just write directly like as follows
label.text=#"\u2794"; // this is the unicode for right arrow
in Swift:
lable.text="\u{2794}"
I am going to develop the iPhone app. But I got stuck with one place. I want to write some symbol on the label from the xib file.
The symbols are not on the keyboard but we can get it by the ASCII value.
e.g: the ACSII value for the character sign "mue" is 230 but how to print that symbol "mue" on the label that i dont know.
So please help me for that.
Thanks in advance.
Use whatever editor you like to produce that character, and open your xib in XCode and just copy/paste it in?
Use NSUTF8StringEncoding to encode your string.
For example,
NSString *str = [NSString stringWithUTF8String:"your string for encoding"];
[lblName setText:str];
Following function will also help :
- (NSString *) decodedString:(NSString *) originalString {
NSString *newString = [NSString stringWithUTF8String:[originalString cStringUsingEncoding:[NSString defaultCStringEncoding]]];
return newString;
}
I suggest to use above function.
Pressing Cmd+Ctrl+Space will open a special characters menu. Check if the desired symbol is present. If it isn't, click the gear icon, then select the desired category — add it to the list.
See screenshot below
I think you mean the character 'µ', yes?
If so, you can simply type it into the label by clicking "option" and "m" on your Macintosh keyboard, when you are editing the label in your XIB.
If you can use the unicode number instead, you can do it like this:
NSString *muString = [NSString stringWithFormat:#"%C", 0x03BC];
Write 0x then the unicode number.
Open the "Special Characters"-Panel and search for your character. You can find it at the bottom of the edit menu. There is a shortcut for it too, cmd+opt+t
Copy and paste your character from there to your UILabel.
and btw: option + m = µ
You can simply type into label by using 'Alt' key + 'm' key on key board, when you are editing the label in your XIB and rest of symbols, you can get easily using 'Alt' key and other keys. You can fix 'Alt' key and change other keys(one by one).
I want to get the last word from the typed sentence in UITextView. For example "Apple i", from this example i need to get the last letter 'i' coming after " "(empty space). I want to do the functionality while the user typing in UITextView. How can i get the users first letter of the word after from empty space(" ")? Can anyone please help to solve this problem? Thanks in advance.
Here is the string logic.
return [[textView.text componentsSeparatedByString:#" "] lastObject];
You can put this check in your UITextViewDelegate method textView:shouldChangeTextInRange:replacementText:. Don't forget to return YES here. You could also use textViewDidChange:.
I retrieve an NSString from a Property list and display it in a UILabel. The NSString already includes \n s, however the UILabel just displays them as text. How can I tell the UILabel to actually use the \n s as line breaks?
Everything you type into a plist in the plist editor is interpreted as plain text. Try it... put a ' into a field and right click -> view as "plain text" and you'll see it substitutes it for '. Therefore you can't put \n into a plist because it thinks you're just typing text and will treat it as such. Instead of putting \n into your plist use Alt+Enter to get your newline. If you view this as a text file now you'll see \ns printed and new lines acctually shown in the text file.
Now when you output it it won't display \n it will just give it a new line.
Plus, as has been mentioned UITextField is only one line anyway and you probably would benefit from using UITextView.
Well, first, you are going to need a string that you can modify. To accomplish that, you can simply do:
NSMutableString* correctedPath = [path mutableCopy];
At that point, you can use -insertString:atIndex: to insert any characters you need.
You're using the wrong class here.
UITextField doesn't (for all that I know) support multi-line input. For that, you will need a UITextView (it has editing enabled by default). It should interpret \n's without any problems. It also has a lineBreakMode property, if you want to make use of that.
I'm having a problem trying to convert a character into a string in Xcode. Here's my code...
NSString *temp = [NSString stringWithFormat:#"%# %# %# = %#", inputOne.text, sign.text, inputTwo.text, answer.text];
self.sign.text is supposed to return either a "+", "-", "*", or "/", which it does. However, I'm trying to have the user post one of these back into facebook via the app. All but the "+" sign will load as a string when they post it to their wall. I don't understand how to get the "+" to show.
I'm guessing that this gets lost since the "+" has a different meaning in javascript. How can I make it a string character in my NSString so that it accepts when posting. Hope this made sense.
I know you can put a quotation mark into a textView by placing a "\" before the quotation. This may work with a "+" sign as well. So the string would look something like this:
#"This is a plus sign \+ in a textView"
Which would return
This is a plus sign + in a textView
Sending "+" over the net (e.g. in GET or, I think, POST) will convert "+" into a space character. To fix, you need to escape the "+" using "%2B".