I created a new project, named yiqi, the project generated a yiqiViewController.xib file through IB, I joined a label, the default text is "welcome", ID is showtxt, has passed the File's Owner point, and then I yiqiViewController.m file write the following code, the purpose is to more than 5 seconds, the welcome text into 1234
@ Implementation yiqiViewController
- (Void) applicationDidFinishLaunching: (id) unused
{
NSTimer * timer = [NSTimer scheduledTimerWithTimeInterval: 5 target: self selector: @ selector (onTimer :) userInfo: nil repeats: NO];
}
- (Void) onTimer: (NSTimer *) timer {
[Showtxt setText: @ "1234"];
}
@ End
When we encounter two problems
One: There is a yellow warning, suggesting that the warning: unused variable 'timer' (text plus red line)
Two: After five seconds later, label display, or welcome, rather than 1234
What does this code wrong place?
Reply:
You do not just create a timer variable use.
start timer is not to have a start method.
Check Apple's documentation.
Reply:
yiqiViewController.m how to call - (void) applicationDidFinishLaunching:? ? ?
You debug, the phrase is being generated timer is running?
I suggest you use - (void) viewDidLoad or - (void) viewWillAppear: and so
applicationDidFinishLaunching: should appDelegate inside.
Reply:
Yes, finally, do not forget to turn off the timer
[Timer invalidate];
timer = nil; / / Make sure you do not have a timer invalidate being used!
No comments:
Post a Comment