Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 11-14-2010, 02:59 AM   #1 (permalink)
Registered Member
 
Join Date: Apr 2010
Location: Germany
Posts: 56
Applekuchen is on a distinguished road
Default HELP! Store time from NSTimer for next ViewController

Hey,

I'm becomming desperate. I've got a NSTimer in my second ViewController.

Code:
-(IBAction)start {
	
	myticker = [NSTimer scheduledTimerWithTimeInterval:0.01 target:self selector:@selector(showActivity) userInfo:nil repeats:YES];
	
}
Code:
-(IBAction)stop {
	
		[myticker invalidate];
		
}
Code:
-(void)showActivity {
	
	float currentTime = [time.text floatValue];
	newTime = currentTime + 0.01;
	time.text = [NSString stringWithFormat:@"%.2f", newTime];        
}
newTime ist an instance variable (float) and time is the label where the time is shown.

Before calling the third ViewController, I stored the time like this:

Code:
-(IBAction)right {
	
	[self stop];
		
	ThirdViewController *screen = [[ThirdViewController alloc] initWithNibName:nil bundle:nil];
	screen.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
	screen.timelabel.text = [NSString stringWithFormat: @"%.2f", newTime];
	[self presentModalViewController:screen animated:YES];
	[screen release];
	
}
I stopped the timer and gave the time to the instance variable timelabel (UILabel).
In the third ViewController I created the same NSTimer with the same methods.
But when I open the third View Controller the timer starts from 0 again.

What's wrong about my code?
Applekuchen is offline   Reply With Quote
Old 11-14-2010, 06:09 AM   #2 (permalink)
Registered Member
 
Join Date: Sep 2010
Location: Skattkärr, Sweden
Posts: 9
BinHex is on a distinguished road
Default

I don't think the UILabel outlet is initiated until the view is loaded. Try to store the time value in a thirdviewcontroller property (screen.timeproperty = [NSString stringWithFormat: @"%.2f", newTime]) that's not an outlet. Then populate the outlet with the timeproperty in viewDidLoad or viewWillLoad.
BinHex is offline   Reply With Quote
Old 11-19-2010, 03:10 PM   #3 (permalink)
Registered Member
 
Join Date: Apr 2010
Location: Germany
Posts: 56
Applekuchen is on a distinguished road
Default

Now I've got in my SecondViewController:

Code:
-(IBAction)start {
	
	myticker = [NSTimer scheduledTimerWithTimeInterval:0.01 target:self selector:@selector(showActivity) userInfo:nil repeats:YES];
	
}


-(IBAction)stop {
	
		[myticker invalidate];
		
}

-(void)showActivity {
	
	currentTime = [time.text floatValue];
	currentTime += 0.01;
	time.text = [NSString stringWithFormat:@"%.2f", currentTime];        
}



-(IBAction)right {
	
	[self stop];
		
	ThirdViewController *screen = [[ThirdViewController alloc] initWithNibName:nil bundle:nil];
	screen.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
	screen.secondTime = [NSString stringWithFormat: @"%.2f", currentTime];
	[self presentModalViewController:screen animated:YES];
	[screen release];
	
}
secondTime is a float ivar in the ThirdViewController and currentTime is a float ivar in the SecondViewController



In my ThirdViewController I've got:

Code:
-(IBAction)start {
	
	myticker = [NSTimer scheduledTimerWithTimeInterval:0.01 target:self selector:@selector(showActivity) userInfo:nil repeats:YES];
	
}


-(IBAction)stop {
	
	[myticker invalidate];
	
}

-(void)showActivity {
	
	float currentTime = [timelabel.text floatValue];
	currentTime += 0.01;
	timelabel.text = [NSString stringWithFormat:@"%.2f", secondTime];        
}
And in the viewDidLoad from the ThirdViewController:

Code:
[self start];
timelabel.text = [NSString stringWithFormat:@"%.2f", secondTime];
When I build the project, an error appears:

error: incompatible type for argument 1 of 'setSecondTime:'

What's wrong?
Applekuchen is offline   Reply With Quote
Old 11-19-2010, 04:10 PM   #4 (permalink)
Registered Member
 
Join Date: Apr 2010
Location: Germany
Posts: 56
Applekuchen is on a distinguished road
Default Solved the Problem!

I solved the problem.

It has to be
Code:
screen.secondTime = self.currentTime;
Applekuchen is offline   Reply With Quote
Reply

Bookmarks

Tags
iphone, nstimer, obj-c, store, xcode

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 371
7 members and 364 guests
apatsufas, Kirkout, lzwasyc, MarkC, Sami Gh, SamorodovAlex, VinceYuan
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,664
Threads: 94,120
Posts: 402,898
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Leslie80
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 02:43 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0