Note that there are some explanatory texts on larger screens.

plurals
  1. POUIPickerView stops NSTimer
    primarykey
    data
    text
    <p>I've been working on a small app that contains only two elements, a <code>UILabel</code> and a <code>UIPickerView</code>.</p> <p>The <code>UILabel</code> is updated by an <code>NSTimer</code> to count down from 60 to 0.</p> <p>The <code>UIPickerView</code> only contains an array of data, don't interact directly with either <code>UILabel</code> with <code>NSTimer</code>.</p> <p>My problem is that when I play with the <code>UIPickerView</code> and I scroll up or down, the counter "animation" stops, continues to make its action until you select an option from the UIPickerView.</p> <p>I could not fix this, I do not know if it's a bug with the iPhone SDK or is there any property as becomeFirstResponder that can help me.</p> <p>I'm using iOS SDK 6.1.</p> <p>This is my code:</p> <p><strong>ViewController.h</strong></p> <pre><code>#import &lt;UIKit/UIKit.h&gt; @interface ViewController : UIViewController &lt;UIPickerViewDataSource,UIPickerViewDelegate&gt;{ IBOutlet UIPickerView *uno; NSMutableArray *numeros; NSTimer *timer; IBOutlet UILabel *contador; int num; } @property (nonatomic, retain) IBOutlet UIPickerView *uno; @property (nonatomic, retain) NSMutableArray *numeros; @property (nonatomic, retain) IBOutlet UILabel *contador; @end </code></pre> <p><strong>ViewController.m</strong></p> <pre><code>#import "ViewController.h" @interface ViewController () @end @implementation ViewController @synthesize uno, numeros, contador; - (void)viewDidLoad { [super viewDidLoad]; numeros = [[NSMutableArray alloc] init]; [numeros addObject:@"0"]; [numeros addObject:@"1"]; [numeros addObject:@"2"]; [numeros addObject:@"3"]; [numeros addObject:@"4"]; [numeros addObject:@"5"]; [numeros addObject:@"6"]; [numeros addObject:@"7"]; [numeros addObject:@"8"]; [numeros addObject:@"9"]; uno.delegate = self; uno.dataSource = self; num = 60; timer = [NSTimer scheduledTimerWithTimeInterval:1.0f target:self selector:@selector(updateCounter:) userInfo:nil repeats:YES]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } - (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)thePickerView { return 1; } - (NSInteger)pickerView:(UIPickerView *)thePickerView numberOfRowsInComponent:(NSInteger)component { return [numeros count]; } - (NSString *)pickerView:(UIPickerView *)thePickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component { return [numeros objectAtIndex:row]; } - (void)pickerView:(UIPickerView *)thePickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component { NSLog(@"Hi"); } - (void)updateCounter:(NSTimer *)theTimer { num = num - 1; [contador setText:[NSString stringWithFormat:@"%d",num]]; } @end </code></pre> <p>The app looks like this: <a href="http://imgur.com/ljB93tN" rel="nofollow">http://imgur.com/ljB93tN</a></p>
    singulars
    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.
 

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