1. UIButton

修改属性一定要有forState。因为按钮有不同的状态

给按钮添加监听用target-action的方式

[btn setXXX forState: UIControlStateNormal];

[btn addTarget:self action:@(selector)action forControlEvent

: UIControlEventTouchUp];

2. 定时任务 3种方法

performSelector

[self performSelector:@selector(hideHUD:) withObject:@"123" afterDelay:2.0];

Dispatch_after

dispatch_after(when, queue, ^{
    xxx;
});

NSTimer

scheduledTimerWith time target selector repeat

//自动开启
self.timer = [NSTimer scheduledTimerWithTimeInterval: 1.5 target:self selector:@select(xx) repeated:NO];

//停止
[self.timer invalidate];
self.timer = nil;

补充 如果再添加一个scrollview,其他scrollview滚动会让当前scrollview停止 ???

解决办法

[[NSRunLoop mainRunLoop]addTimer:self.timer forMode:NSRunLoopCommonModes];

3. 加载plist文件

1.获取mainBundle 2.获取plist 3.读取plist

NSBundle *bundle = [NSBundle mainBundle];
NSString *file = [bundle pathForResource:@"shops" ofType:@"plist"];
self.array = [NSArray arrayWithContentOfFile:file];

results matching ""

    No results matching ""