using nstimer in viewcontroller
<p>I have a scenario where I need to start/stop a timer on a button click. I may move from the page and come back again but the timer should be running. For this purpose I am stoping and releasing it in viewWillDisappear method and restarting it on the basis of a condition in viewWillAppear. But It is not getting started again. Following is my code:</p>

<pre><code>- (void)viewWillDisappear:(BOOL)animated {
if([timerInterval isValid]) {
    [timerInterval invalidate];
    //[timerInterval release];
    timerInterval = nil;
}
</code></pre>

<p>}</p>

<pre><code>- (void)viewWillAppear:(BOOL)animated {
HealthyBabyAppDelegate *appDel = (HealthyBabyAppDelegate *)[[UIApplication sharedApplication] delegate];
self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:[appDel changeBackground]]];
if(appDel.contractionDutation&gt;0) {
    //if(timerInterval==nil)
    timerInterval = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(printInterval) userInfo:nil repeats:YES];
}
</code></pre>

<p>}</p>

<pre><code>-(IBAction)Contraction:(id)sender {
HealthyBabyAppDelegate *appDel = (HealthyBabyAppDelegate *)[[UIApplication sharedApplication] delegate];
if([(UIButton*)sender tag]==2) {//stop the contrction
    [(UIButton*)sender setTag:1];
    [(UIButton*)sender setTitle:@"Start" forState:UIControlStateNormal];
    [appDel startContractionTimer:FALSE];
    [timerInterval invalidate];
    //timerInterval = nil;
}
else {//start the contraction, 2 means contraction is running
    [(UIButton*)sender setTag:2];
    [(UIButton*)sender setTitle:@"Stop" forState:UIControlStateNormal];
    [appDel startContractionTimer:TRUE];
    ([[tblContractionDetail cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]] textLabel]).text = [NSString stringWithFormat:@"Start Time: %@",appDel.contractionStartTime];
    timerInterval = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(printInterval) userInfo:nil repeats:YES];
}
</code></pre>

<p>}</p>

<pre><code>Contraction method will stop/delete the timer. 
</code></pre>

<p>Thanks
Pankaj</p>
