adding subview to different class
I am making a test app. Right now I have a timer in the application didFinishLaunching
.
Here is my code:
-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{ timelabel =开发者_JS百科 [[UILabel alloc] initWithFrame:CGRectMake(20, 80, 280, 120)];
[self.view addSubview:timelabel];
[timelabel.text isEqualToString:@"0"];
time = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self
selector:@selector(timervoid) userInfo:nil repeats:YES];
}
-(void)timervoid {
int now;
now = [timelabel.text intValue];
int after;
after = now + 1;
timelabel.text = [NSString stringWithFormat:@"%i", after];
}
I need the timer to continue through all classes, which is why I put it in the app delegate application didFinishLaunching
, but how can I add it to the class's view?
You can use UIApplication sharedApplication to access the timer which u have declared in the appDelegate class.
Hope this helps
Happy Coding !
精彩评论