I would have to use a necessiva progressView for the management of a small form. In a nutshell I have several actions that the user must carry through a click of UIButton and these actions should increase the progressview until completion . Let me give an example :
Let's start with a progressView set to 0.3
Button 1 is clicked and doing the action increases the progressview of 0.1 , so the progress is updated up to 0.4
The button 2 is clicked and increased by another 0.1 , and then the progressview becomes 0.5.
That's what I should do ... Currently I am stuck because if I make these actions I find myself 0.3 ( starting ) to 0.1 instead of me that serves 0.1 increments to any button is pushed ..
How can I solve the problem ... ? ? I'll post a little ' code
- (Void) viewDidLoad
{
[super viewDidLoad ] ;
FFProgressBar.progress = 0.3 ;
}
- ( IBAction ) FFAddVotazione : (id ) sender {
if ( FFVariabileNumerica_CFU_Votazione > = 30 )
return;
FFVariabileNumerica_CFU_Votazione + + ;
[ FFVotazioneLabel setText : [ NSString stringWithFormat : # " % d", FFVariabileNumerica_CFU_Votazione ]] ;
[ FFProgressBar setProgress : +0.1 ] ;
}
- (IBAction)FFAddCFU:(id)sender {
if (FFVariabileNumerica_CFU_Votazione >= 30)
return;
FFVariabileNumerica_CFU_Votazione++ ;
[FFCFULabel setText:[NSString stringWithFormat:#"%d", FFVariabileNumerica_CFU_Votazione]];
[FFProgressBar setProgress:+0.1];
}
Related
I am new to Objective-C and I made an up counter. By tapping on a button it will increment by one and made another button to reset to 0 but the problem is I could not make is stop in a spacific number e.g I want it when it reaches 15 reset again to zero
-(IBAction)up:(id)sender{
numbercount = numbercount +1 ;
counterdisplay.text = [NSString stringWithFormat:#"%i" , numbercount];
}
-(IBAction)reset:(id)sender{
numbercount = 0 ;
counterdisplay.text = [NSString stringWithFormat:#"%i" , numbercount];
that is my project
Let's say the you have the value of your counter stored in a variable, say, counterValue.
Every time you add 1 to counterValue, simply check if the new value equals 15, and if it does, reset the value back to 0.
- (void)buttonTapped {
counterValue++;
if(counterValue == 15) {
counterValue = 0;
}
}
I can't give you a more specific example because you didn't share your current code, so hopefully this is enough to get you started in your own project.
Welcome to Stack Overflow!
I have a button connected to a UiProgressView, has only the function to count the clicks on the button ... I need to show the percentage of completion in a UILabel .. Can you tell me which method is better?
To make you understand the function I show you the code of the IBAction
- (IBAction)FFAddCFU:(id)sender {
if (FFVariabileNumerica_CFU >= 30)
return;
FFVariabileNumerica_CFU++ ;
[FFCFULabel setText:[NSString stringWithFormat:#"%d", FFVariabileNumerica_CFU]];
if(FFProgressBar.progress == 0.50 || FFProgressBar.progress == 0.77 ){
[ FFProgressBar setProgress : FFProgressBar.progress +0.25 ];
} else {
if (FFProgressBar.progress > 0.76) {
[ FFProgressBar setProgress : FFProgressBar.progress +0.25 ]; }
}
}
I've done this in a small project of mine for a custom progress view. It can be found at lightdesign/LDProgressView. You can take a look at the file LDProgressView.m for how I've done this.
Here's the relevant line:
label.text = [NSString stringWithFormat:#"%.0f%%", self.progress*100];
This line takes the progress value which is between 0.0 and 1.0 and multiplies it by 100 and then inserts the number up to the whole number (.0 in the format string) with a percentage at the end (%% in the format string).
Also, if you don't want to manually calculate the percentage, feel free to use the open source control I've made.
I have the following code:
- (NSArray *)checkNormalGameDuelAndMatch:(float)nrDuelQs andNrQPerDuel:(float)nrQPerDuel andNrMatchQ:(float)nrMatchQ andActivePlayer:(float)actPlayerNrQ andInactivePlayer:(float)inactivePlayerNrQ {
NSLog(#"checkNormalGameDuelAndMatch:");
// Check for Matches and Duels to prep for swaps and/or match endings
NSArray *theCheckArray = [[NSArray alloc]init];
NSLog(#"nrDuelQs: %.0f / nrQPerDuel: %.0f", nrDuelQs, nrQPerDuel);
// Check if Match still on
NSLog(#"actPlayerNrQ: %.0f / inactivePlayerNrQ: %.0f / nrMatchQ: %.0f", actPlayerNrQ, inactivePlayerNrQ, nrMatchQ);
if (actPlayerNrQ < nrMatchQ && inactivePlayerNrQ < nrMatchQ) {
// Match is still on
_isMatchStillOn = YES;
// Check if Duel is till on
if (nrDuelQs < nrQPerDuel) {
// Duel is still on
_isDuelStillOn = YES;
NSLog(#"_isDuelStillOn = YES;");
}
else {
_isDuelStillOn = NO;
NSLog(#"_isDuelStillOn = NO;");
}
}
else {
//==MATCH IS OVER==//
_isMatchStillOn = NO;
NSLog(#"MATCH OFF");
}
theCheckArray = #[[NSNumber numberWithBool:_isDuelStillOn], [NSNumber numberWithBool:_isMatchStillOn]];
return theCheckArray;
}
With the following NSLog output, during two loops:
checkNormalGameDuelAndMatch:
nrDuelQs: 4 / nrQPerDuel: 5
actPlayerNrQ: 4 / inactivePlayerNrQ: 0 / nrMatchQ: 5
_isDuelStillOn = YES;
checkNormalGameDuelAndMatch:
nrDuelQs: 5 / nrQPerDuel: 5
actPlayerNrQ: 5 / inactivePlayerNrQ: 0 / nrMatchQ: 5
MATCH OFF
I guess there is something wrong with the If-statement and "&&" as i am not expecting the "MATCH OFF" when it comes.
I guess i am blind as this should not be complicated.
This is very likely happening because the variables are of the type float: even through they both print as 5, one of them may be actually slightly smaller than the other (say, 4.9999999999999999). This could happen because of the way actPlayerNrQ is calculated: for example, if you add 0.1 fifty times, you would not get exactly a 5.
Here is a link to an example (it is in C, but that part of the language is shared with Objective C).
float n = 0;
int i = 0;
for (i = 0 ; i != 25 ; i++, n += 0.2);
printf("%f < 5.000000 : %s", n, n < 5.0 ? "yes":"no");
This prints
5.000000 < 5.000000 : yes
To fix this, you could compare with an epsilon, for example
#define EPSILON 1E-8
// 1E-8 stands for 1*10^-8, or 0.00000001
...
if ((actPlayerNrQ - nrMatchQ) < EPSILON && (inactivePlayerNrQ - nrMatchQ) < EPSILON)
...
I am using a NSStepper along with a NSTextField. The user can either set the value using the text field or can use the NSStepper to change the value. I will quote my question using the example below:
Suppose the current value of my stepper is 4 and increment value of the stepper is 2:
After I click the UP arrow on the NSStepper the value becomes:
Now Suppose the current value would have been 4.5 i.e.:
After using the UP arrow the value becomes:
What I require is that when the current value is 4.5, after using the UP arrow, the value becomes 6 instead of 6.5
Any ideas to accomplish this are highly appreciated!
What I require is that when the current value is 4.5, after using the
UP arrow, the value becomes 6 instead of 6.5
Hard to tell exactly what you are asking but taking a guess: it sounds like you want to remove the decimal part of the number and increment by your defined step amount (2). You can do this through the floor() function. See here for other Objective-C math functions
double floor ( double ) - removes the decimal part of the argument
NSLog(#"res: %.f", floor(3.000000000001));
//result 3
NSLog(#"res:%.f", floor(3.9999999));
//result 3
If I understand what you want, this code will give you the next even number (up or down depending on which arrow you click), but still allow you to enter non-integer numbers in the text filed. tf and stepper are IBOutlets and num is a property (a float) that keeps track of the value of the stepper before you click an arrow so you can compare with the new number to see if the up or down arrow was clicked.
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
self.num = 0;
self.tf.intValue = 0; //the stepper is set to 0 in IB
}
-(IBAction)textFieldDidChange:(id)sender {
self.num = self.stepper.floatValue = [sender floatValue];
}
-(IBAction)stepperDidChange:(id)sender {
if (self.num < self.stepper.floatValue) { //determines whether the up or down arrow was clicked
self.num = self.stepper.intValue = self.tf.intValue = [self nextLargerEven:self.num];
}else{
self.num = self.stepper.intValue = self.tf.intValue =[self nextSmallerEven:self.num];
}
}
-(int)nextLargerEven:(float) previousValue {
if ((int)previousValue % 2 == 0) {
return (int)previousValue + 2;
}else
return (int)previousValue + 1;
}
-(int)nextSmallerEven:(float) previousValue {
if ((int)previousValue % 2 == 0) {
if ((int)previousValue == previousValue) {
return (int)previousValue - 2;
}else{
return (int)previousValue;
}
}else
return (int)previousValue - 1;
}
So I have a method that is suppose to make an an object move up rapidly. The code inside is :
b2Vec2 force;
force.Set(_body->GetLinearVelocity().x, _body->GetLinearVelocity().y+1.0f);
for (b2Body* b = _game.world->GetBodyList(); b; b = b->GetNext())
{
if (b->GetUserData() == character)
{
b->SetLinearVelocity(force);
}
}
The code is not important, I want to know how I can stop this process after a few seconds or once it reaches a certain y point. because atm it runs out of the screen!
Regards.
Just test if the y position of the body is below the threshold you don't want it to cross:
for (b2Body* b = _game.world->GetBodyList(); b; b = b->GetNext())
{
if (b->GetUserData() == character && b->GetPosition().y < 300)
{
b->SetLinearVelocity(force);
}
}
What you can do is create an nstimer for periodically calling the selector which has your code and put it in repeat mode.
this will go on forever.. so in order to stop it after a particular amount of time put this entire thing in a new method and call that method inside a new nstimer.
so basically a timer inside a timer.