How to keep Placeholders even after clearing all textfields - ios

So I have 3 textfields. After they are cleared, I would like the placeholder to STILL remain there. So far for about the past week I've been fighting with this issue and no one is able to help me solve it. I was wondering if this is even possible?...
Here is my sample code to set the placeholder after clearing it:
personYouOweMoney.text = #" ";
amtYouOwe.text = #" ";
self.cellNum.text = #" ";
personYouOweMoney.placeholder = #"Name of person you owe";
amtYouOwe.placeholder = #"Amount Owed (USD)";
self.cellNum.placeholder = #"Their cell number";
All help is appreciated, thanks in advance

You are basically setting the textField's text to a single space so, technically, it ain't empty.
(Only when the textField is empty will the placeholder will be seen)
Do:
//set the placeholder's and when you want to clear the textfield, this...
personYouOweMoney.text = #"";
amtYouOwe.text = #"";
self.cellNum.text = #"";

Related

Textview will not add text on load

I've been spending hours trying to get my textview to load with text from a string when loading but it always appears blank but when I do it through button action it works fine.
Is this a known issue or is there even a solution?
Here is the code. NSLog does show the string contents.
Variables *GetVariables = [Variables SharedInstance];
NSString *Text = GetVariables.FileText;
NSLog(#"%#", Text);
_MyTextField.text = Text;

Changing the text of a label on button press with dynamic integer

I'm following a tutorial to create a simple game where you tap a button and the the game counts how many times you have pressed the button as you go along. The score is displayed on screen in the form of a label.
I can make it so that when you press the button the label text changes to say 'Pressed!'. But then i can not get the label to change when i try to add the changing score with a format specifier.
-(IBAction)buttonPressed{
count ++;
//scoreLabel.text =#"pressed";
scoreLable.text = [NSString stringWithFormat:#"Score\n%i", count];
}
Any help would be greatly appreciated. Thanks!
You may not have your label set up for multiple lines of text. Try getting rid of the "\n" in your format string. Other than that, you need to tell us what happens. Have you put a breakpoint to make sure your button IBAction is being called? Have you checked to make sure "scoreLable" (sic) is not nil? The devil is in the details.
-(IBAction)buttonPressed : (id) sender{
UIButton * btnPressed = (UIButton *)sender;
int buttonValue = [[btnPressed titleForState:UIControlStateNormal] intValue];
NSLog(#"Button value = %d", buttonValue);
//scoreLabel.text =#"pressed";
scoreLable.text = [NSString stringWithFormat:#"Score\n%i", count];
}
First You Can Set static int count = 0;

Adding label text together

Hi im relatively new to iOS and I'm just wondering how i would add two labels together.
- (IBAction)switch1
{
if (switch1.on) {
value1.text = #"3";
} else {
value1.text = #"0";
}
}
- (IBAction)switch2
{
if (switch2.on) {
value2.text = #"3";
} else {
value2.text = #"0";
}
}
As you can see i have used two switches which would show two different values if they were turned on or off.
Could someone help me understand how i would add two values together.
I.e if switch one was on and switch two was off the value would be three i want this value to be shown in another label.
So far i have come up with this but for some reason it doesn't work, i have a feeling it is the format specifier but I'm not sure.
int sum = [[value1 text] intValue] + [[value2 text] intValue];
value3.text = [NSString stringWithFormat:#"%d", sum];
Dont you have this:
int sum = [[value1 text] intValue] + [[value2 text] intValue];
value3.text = [NSString stringWithFormat:#"%d", sum];
in ViewDidLoad or something? Because you have to call this at the end of both IBActions. If you don't, your final value will never change.
Make sure you properly created an outlet connection in Interface Builder as described here:
Creating an Outlet Connection
In short words. Ctrl+Click & Drag from the UISwitch to File’s Owner and click the new switch1 or switch2 action. Create outlets for the text fields and switches and link them.
Set breakpoints in switch1 and switch2 methods and ensure there are being called.
Use po command in the console to check if the text fields and switches are configured correctly.
For example:
po _textField1
should print text field's description. It will print nil when the text field is not there - not linked to a control in interface builder.

Adding text to an already populated UITextView

Really quick, easy question.How do I add text to a UITextView, when it's already populated.
E.G., but doesn't work: _textView.text=+#"";
Thanks,
SebOH
_textView.text = [_textView.text stringByAppendingString:#""]
_textView.text = [_textView.text stringByAppendingString:#"Additional Text"];
_textView.text = [NSString stringWithFormat:#"%#%#",_textView.text,#"text you want to append"];
using above you can add the text where ever you want prefix,postfix ..

Why not work my UITableViewCell Subclass?

I'm trying to make a TableView with a CustomCell, I get the data of a XML web service, I'm parsing whole fine, but when I like show the data in my UITableViewCell subclass only can see the image, the labels not appear, I have the Oulets and instances correctly but just it not work .
Respository with the code
I leave a bitbucket repository to check my code, please help me, I think that is a small error but is hard to solve to me.
Thanks in advance.
Your labels begin with a newline character, for example:
__NSCFString * #"\n Casas de empeño ‘exprimen’ a deudores" 0x08cb7c10
You can solve this by trimming white space:
cell.cabezaLbl.text = [[dic objectForKey:#"Cabeza"] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
NSString *str = [dic objectForKey:#"Entrada"]
str is like "\n bla bla bla" so your label should be show multiple lines. You should set numberOfLines property of this label 0.
cell.entradaLbl.numberOfLines = 0;
Or you can do this in interface builder.

Resources