Note that there are some explanatory texts on larger screens.

plurals
  1. POChanging labels after swithiching between views
    primarykey
    data
    text
    <p>I have two-views app for iPhone. On first one I call code that does this every second with NSTimer:</p> <ol> <li>update variables</li> <li>make sound</li> <li>update label</li> <li>update image position</li> </ol> <p>When I start app - everything works perfect. When I go to other view and then go back to first screen - 1 and 2 works fine, but 3 and 4 resets and does not work at all. </p> <p>What could be the problem?</p> <p>Looks like it loses "hooks" to elements... </p> <pre><code>-(void)countup { DeccelFloat += 0.4; SpeedFloat += 5/(DeccelFloat); SpeedInt = lroundf(SpeedFloat); speed.text = [NSString stringWithFormat:@"%i", SpeedInt]; imageview.center = CGPointMake(imageview.center.x, imageview.center.y+3); if (imageview.center.y &lt; 280) { imageview.alpha = 1; if (SpeedFloat &gt; MaxSpeedValue) { [self playalarm]; }else{ [self playbeep]; } } if ((imageview.center.y &gt;= 280) &amp;&amp; (imageview.center.y &lt; 283)) { if (SpeedFloat &gt; MaxSpeedValue) { [self playshot]; }else{ [self playbeepbeep]; } } if ((imageview.center.y &gt;= 280) &amp;&amp; (imageview.center.y &lt; 350)) { imageview.alpha = 0.5-(0.5/70)*(imageview.center.y - 280); } if (imageview.center.y &gt;= 350) { imageview.alpha = 0; imageview.center = CGPointMake(imageview.center.x, 180); } } </code></pre> <p>And here is my timer:</p> <pre><code>- (void)viewDidLoad { [super viewDidLoad]; MaxSpeedValue = 60; NSUserDefaults *standardUserDefaults = [NSUserDefaults standardUserDefaults]; NSNumber *maxspeedsetttings = nil; NSNumber *blinkingsetttings = nil; NSNumber *startedsetttings = nil; if (standardUserDefaults) { maxspeedsetttings = [standardUserDefaults objectForKey:@"maxspeedsetttings"]; blinkingsetttings = [standardUserDefaults objectForKey:@"blinkingsetttings"]; startedsetttings = [standardUserDefaults objectForKey:@"startedsetttings"]; } MaxSpeedDef = [maxspeedsetttings intValue]; if (MaxSpeedDef == 1) { maxspeed.text = [NSString stringWithFormat:@"%i", MaxSpeedValue]; }else{ maxspeed.alpha = 0; maxspeedlabel.alpha = 0; } imageview.animationImages = [NSArray arrayWithObjects: [UIImage imageNamed:@"0.png"], [UIImage imageNamed:@"5.png"], [UIImage imageNamed:@"10.png"], nil]; imageview.animationDuration = 1; imageview.animationRepeatCount = 0; BlinkingDef = [blinkingsetttings intValue]; if (BlinkingDef == 1) { [imageview startAnimating]; }else{ [imageview stopAnimating]; } [self.view addSubview:imageview]; StartedDef = [startedsetttings intValue]; if (StartedDef == 0) { SpeedFloat = 0; DeccelFloat = 0; timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(countup) userInfo:nil repeats:YES]; StartedDef = 1; if (standardUserDefaults) { [standardUserDefaults setObject:[NSNumber numberWithInt:StartedDef] forKey:@"startedsetttings"]; [standardUserDefaults synchronize]; } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload