随笔 - 91,  文章 - 0,  评论 - 4,  阅读 - 13万

 

复制代码
 1 #import "ViewController.h"
 2 
 3 static NSInteger count = 0;
 4 
 5 @interface ViewController ()
 6 
 7 @property (weak, nonatomic) IBOutlet UILabel *label;
 8 
 9 @property (nonatomic, strong)NSArray *array;
10 /** 添加定时器 */
11 @property (nonatomic, strong) NSTimer *time;
12 
13 @end
14 
15 @implementation ViewController
16 
17 - (NSArray *)array
18 {
19     if(!_array)
20     {
21         _array = [NSArray arrayWithObjects:@"1...",@"2....",@"3.....",@"4......", nil];
22     }
23     return _array;
24 }
25 
26 - (void)viewDidLoad {
27     [super viewDidLoad];
28     
29     self.time = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(runLabel) userInfo:nil repeats:YES];
30     [self.time fire]; // 立即触发定时器
31 //    [time setFireDate:[NSDate distantPast]]; // 开启定时器
32 //    [time setFireDate:[NSDate distantFuture]]; // 暂停定时器
33 }
34 
35 - (void)runLabel
36 {
37     self.label.text = self.array[count++ % self.array.count];
38 }
39 
40 /** 移除定时器 */
41 - (void)removeTimer
42 { // 定时器一旦被停止,不会重新开始,要被移除。
43     [self.time invalidate];
44     self.time = nil;
45 }
46 - (void)didReceiveMemoryWarning {
47     [super didReceiveMemoryWarning];
48     // Dispose of any resources that can be recreated.
49 }
50 
51 @end
复制代码



posted on   xiao孛  阅读(377)  评论(0编辑  收藏  举报
编辑推荐:
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· DeepSeek 开源周回顾「GitHub 热点速览」
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示