将子视图添加到不同的类

时间:2011-07-13 07:00:19

标签: iphone objective-c xcode nstimer

我正在制作测试应用。现在我在应用程序didFinishLaunching中有一个计时器。

这是我的代码:

 -(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
  {     timelabel = [[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];

 }

我需要计时器才能继续浏览所有类,这就是我将它放在app delegate application didFinishLaunching中的原因,但是如何将它添加到类的视图中呢?

1 个答案:

答案 0 :(得分:1)

您可以使用UIApplication sharedApplication来访问您在appDelegate类中声明的计时器。

希望这有帮助

快乐的编码!

相关问题