繁体   English   中英

将子视图添加到不同的 class

[英]adding subview to different class

我正在制作一个测试应用程序。 现在我在应用程序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];

 }

我需要计时器继续通过所有类,这就是为什么我把它放在应用程序委托应用程序didFinishLaunching中,但是我怎样才能将它添加到类的视图中呢?

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

希望这可以帮助

快乐编码!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM