Hello! I have a little problem I was hoping the community could help me with.
-
In
CounterviewController, I have one label and two Buttons “Add” and “Sub”. By pressing the Sub button it decrements the value normally but I need to stop with 0 (don’t go below zero to -1,-2,-3,-4). -
Then I need to display the
countLabelvalue into thePreviousViewlabel. Can you please help me?
Here’s my code:
(IBAction)decrementNumber:(id)sender
{
number--;
[currentNumber setText:[NSString stringWithFormat:@"%d", number]];
}
Could you please point out where my error is?
Thanks in Advance,
Padmavathi CP.
For your first question, only decrement and display if the number is greater than zero:
For your second question, the method may well depend on your object types. For example, for transfers between two
NSTextFieldobjects (or others based onNSControl), you could use something like: