Hi , thankyou for your time.
But I'm quite new to this.
After I delete the id sender part. Than what is "call Calculate on each timer click"
Could you please give an example ?
Thankyou very much
Quote:
Originally Posted by aldcorn@live.com
Put this code in function without the id)sender part
Then call self Calculate on each timer click.
Otherwise just have this action fire anytime any of the text or num ers change.
Or do this on the view did load.
It all depends where and when you are getting the values.
Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.
Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.
I can't answer that because I don't know when you want that code to be invoked.
Figure out what you want to trigger the code, and then you can decide where to put the call.
Thankyou , As I said , I'm new to it.
So I don't really understand what you mean.
Just the code from above is implemented in the .m file of the main window.
When I run the app , I first need to press a button so that it calculates. What I have is a textfield(= divider) a label(= number) and a another label(= result).
I want that after putting a number in the textfield (for example : 8) and the value of the label is 16 , that its result (= 2) is in the label. This is al right , but I first need to press the button for to display the result.
What I want is that after puttung a number in the textfield , it is automaticly calculating (dividing) without pressing any button and giving the result in the label.
Thankyou , As I said , I'm new to it.
So I don't really understand what you mean.
Just the code from above is implemented in the .m file of the main window.
When I run the app , I first need to press a button so that it calculates. What I have is a textfield(= divider) a label(= number) and a another label(= result).
I want that after putting a number in the textfield (for example : 8) and the value of the label is 16 , that its result (= 2) is in the label. This is al right , but I first need to press the button for to display the result.
What I want is that after puttung a number in the textfield , it is automaticly calculating (dividing) without pressing any button and giving the result in the label.
Do you need more information ?
Thankyou for your time
Ok, so call
Code:
[self Calculate: nil];
In each of those cases.
Add that call in your view controller's -viewWillAppear method. That will take care of generating the message when the view is first displayed.
To get notified when the user changes the value of your different text fields, you need to do a couple of things:
Add the string <UITextFieldDelegate> to the @interface declaration of your view controller, like this:
That tells the system that your view controller supports the UITextFieldDelegate protocol. That means that your view controller knows how to respond to certain messages the text field might send it. All the methods in that protocol are optional, so you don't actually have to respond to any of the messages.
Connect the "delegate" outlet on your text fields to "file's owner" in interface builder.
The textFieldDidEndEditing: message is one of the messages that a UITextField can send it's delegate. It tells you that the user is finished making a change to the contents of the text field. In our case, we just use it to trigger your calculate method.
Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.
- (IBAction)Total{
float x = ([billTotal.text floatValue]);
float c = x+([tipAmount.text floatValue]);
total.text = [[NSString alloc] initWithFormat:@"%2.f", c];
}
But It didn't worked.
Here , it will display the sum of a textfield + a label.
How do I have to do here that I don't have to press ?
What do you mean "It didn't worked."? What happens? Does the total text field change at all?
The code looks like it should be adding the values. If the result isn't changing, I would make sure that "total" is not nil at run-time. (Set a breakpoint at the line that assigns a value for total.text and examine the value of "total")
If total is changing, but you're getting the wrong answer, check that the billTotal and tipAmount variables are not nil.
The most likely problem is that the outlets to these text fields is not set up in Interface Builder.
By the way, your code has memory leaks.
When you create a string with alloc/init, or initWithFormat, you have to release it when you are done with it. Better to use the stringWithFormat method, that creates an auto-released string:
Methods with init, new, or copy in their name create objects with a retain count of 1, and you must release them when you are done with them. (You own them)
All other methods return objects that you do not own. You need to send them a retain message if you want to make sure they don't go away in the near future.
In the case of assigning a string to total.text, you want a temporary string that will go away automatically.
Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.
I have a texfield and 2 labels.
In the texfield I set 100 , the tipAmount label is set to 5.00 so after the press on button the total label wil be 105. So it's changes
By the way , thanks for your tip , I've changed the code
I have a texfield and 2 labels.
In the texfield I set 100 , the tipAmount label is set to 5.00 so after the press on button the total label wil be 105. So it's changes
By the way , thanks for your tip , I've changed the code
Sigh...
TO REPEAT: WHAT HAPPENS WHEN YOU CLICK THE BUTTON OR OTHERWISE INVOKE THE METHOD? Does it not change the text? Does it display the wrong answer? And what happens when you set a breakpoint at the beginning of the method and step through the code?
Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.