Paste_Image.png 8.关于代理协议的一些细节 协议可以继承其他协议,并且可以继承多个协议,在iOS中对象是不支持多继承的,而协议可以多继承。...的总结 线程无关方法 - (id)performSelector:(SEL)aSelector; - (id)performSelector:(SEL)aSelector withObject:(id...)object; - (id)performSelector:(SEL)aSelector withObject:(id)object1 withObject:(id)object2; 这三个方法,...Delayed perform - (void)performSelector:(SEL)aSelector withObject:(id)anArgument afterDelay:(NSTimeInterval...)delay inModes:(NSArray *)modes; - (void)performSelector:(SEL)aSelector withObject:(id)anArgument afterDelay
unknown 所以在实际开发中,为了避免运行时突然报错找不到方法等问题,少使用performSelector方法。...而performSelector:withObject:afterDelay:其实就是在内部创建了一个NSTimer,然后会添加到当前线程的Runloop中。...[self performSelector:@selector(test) withObject:nil afterDelay:2]; 如果在子线程中调用该performSelector延迟方法,会发现调用该延迟方法的子线程和...test方法中执行的子线程是同一个,也就是说: 对于该performSelector延迟方法而言,如果在主线程中调用,那么test方法也是在主线程中执行;如果是在子线程中调用,那么test也会在该子线程中执行...在回答完延迟方法之后,会将该方法和performSelector:withObject:作对比,那么performSelector:withObject:在不添加到子线程的Runloop中时是否能执行?
[self performSelector:@selector(completion) withObject:nil afterDelay:0]; NSLog(@"2"); }); - (void...看一下官方文档说明: 这个方法会在当前线程的 runloop 中创建一个计时器来执行该消息。...如果希望消息能在其他模式下也能出列,可以使用performSelector:withObject:afterDelay:inModes: 代替。...如: [self performSelector:@selector(test) withObject:nil afterDelay:2 inModes:@[NSRunLoopCommonModes]]...:withObject:waitUntilDone:modes: 方法确保函数在主线程上执行。
withObject:(id)object; – (id)performSelector:(SEL)aSelector withObject:(id)object1 withObject:(id)object2...afterDelay:(NSTimeInterval)delay inModes:(NSArray *)modes; – (void)performSelector:(SEL)...aSelector withObject:(nullable id)anArgument afterDelay:(NSTimeInterval)delay; 这两个方法为异步执行,只能在主线程中执行...注意:apple不允许程序员在主线程以外的线程中对ui进行操作,此时我们必须调用performSelectorOnMainThread函数在主线程中完成UI的更新 4、 – (void)performSelector...; 在我们指定的线程中调用方法。
(顺便说一下performSelector其他方法) 二、performSelector 1、afterDelay在子线程中未执行 2、实现:多次点击, 只执行最后一次 三、需要手动加锁(线程同步)(...在子线程中未执行 - (void)afterDelayNowork { // 模拟子线程里执行 afterDelay 方法 dispatch_async(dispatch_get_global_queue...@selector(complete) withObject:nil afterDelay:0]; NSLog(@"2"); // 在子线程里获取一下runloop NSRunLoop...: withObject: afterDelay: 1....:) object:nil]; [self performSelector:@selector(afterDelay:) withObject:nil afterDelay:2]; // 2s后执行
是否具备开启新线程的能力 串行队列 (单行线) 任务一个接一个 无论同步还是异步 (无论有没有超车能力都只能一条线) ==队列(串行并发) 决定了运行方式== ==同步异步 决定了能否开启新线程的能力 (主队列只在主线程...:@selector(test) withObject:nil afterDelay:0]; NSLog(@"3"); }); } - (void) test { NSLog...233631] 1 2019-09-01 17:55:37.963250+0800 GCD[16903:233631] 3 复制代码 分析原因: 未执行原因:RunLoop未开启 消息添加到RunLoop中也不会被调用...performSelector: withObject: 底层调用[self msgSend]; performSelector: withObject:afterDelay; RunLoop相关 往RunLoop...:@selector(test) onThread:thread withObject:nil waitUntilDone:YES]; NSLog(@"3"); } - (void) test
)sender { dispatch_async(dispatch_get_global_queue(0, 0), ^{ NSLog(@"1"); [self performSelector...:@selector(test) withObject:nil afterDelay:0]; NSLog(@"2"); }); } - (void)test { NSLog...(@"3"); } 答案是只打印:1、2 因为[self performSelector:@selector(test) withObject:nil afterDelay:.0]实际在runloop里面...,是一个定时器,但是因为在子线程,runloop是默认没有开启的。...实现原理: 当调用 NSObject 的 performSelecter:afterDelay: 后,实际上其内部会创建一个 Timer 并添加到当前线程的 RunLoop 中。
在滚动到底部的时候停止NSTimer。每当手动滚动UITextView前销毁NSTimer,滚动后重新创建NSTimer。...NSTimer *timer; - (void)viewDidLoad { [self performSelector:@selector(resetText) withObject:nil afterDelay...UIScrollView *)scrollView { [timer invalidate]; timer = nil; NSLog(@"scrollViewWillBeginDragging"); [self performSelector...:@selector(resetText) withObject:nil afterDelay:3.0f]; } - (void) onTick:(NSTimer*)theTimer { CGPoint
思路1:采用 performSelector 相关的API: 这么多API,可以采用一个适合的,例如: - (void)performSelectorOnMainThread:(SEL)aSelector...withObject:(id)arg waitUntilDone:(BOOL)wait; 其中 waitUntilDone 后面的BOOL参数。...当为YES的时候,先让主线程运行aSelector中的一些操作,之后再进行当前线程中的操作。 当为NO的时候,先进行当前线程中的操作,之后让主线程运行aSelector中的一些操作。...:) withObject: array afterDelay:15.0]; 方法二: 使用NSInvocation SEL aSelector = NSSelectorFromString(@"doSoming...:@selector(invoke) withObject:nil afterDelay:15.0]; } 3.
1 UIRefreshControl实现 1.1 使用范围 如果你装了xcode_4.5_developer_preview,那么在UITableViewController.h文件中你会看到...[self performSelector: @selector(handleData) withObject: nil afterDelay: 2]; 在handleData里面,就表示已经请求到了数据...: @selector(refreshTable) withObject: nil afterDelay: 3.0f]; } - (void) pullTableViewDidTriggerLoadMore...: (PullTableView *)pullTableView { [self performSelector: @selector(loadMoreDataToTable) withObject...: @selector(refreshTable) withObject: nil afterDelay: 3]; } 3 MJRefresh https://github.com/CoderMJLee
1.1 原理分析 1.2 代码实现 1.3 使用和测试 引言 在项目开发中,会对数据库数据进行更新操作的接口请求,不仅服务器侧需要控制请求频率以及保证数据的唯一性和一致性,app侧也需要进行限制来避免测试垃圾数据...} }]; [self addGestureRecognizer:cutTap]; 倒计时巧妙地使用performSelector...:withObject:afterDelay:实现 [self performSelector:@selector(resetState) withObject:nil afterDelay
在iOS开发中,我曾遇到这样一个问题,很久都未能解决,就是在cell上添加一个button,当我们点击button时,它是没有高亮效果的,除非我们长按button,我这里整理一下解决这个问题的方法 原文链接...:@selector(setDefault) withObject:nil afterDelay:0.1]; } -(void)touchesEnded:(NSSet *)touches...withEvent:(UIEvent *)event{ [super touchesEnded:touches withEvent:event]; [self performSelector...:@selector(setDefault) withObject:nil afterDelay:0.1]; } - (void)setDefault { [NSOperationQueue.mainQueue...addOperationWithBlock:^{ self.highlighted = NO; }]; } 该方案比较简单粗暴,我们创建一个UIButton的分类,然后将它导入pch文件中,就彻底解决了
引言 在项目开发中,会对数据库数据进行更新操作的接口请求,不仅服务器侧需要控制请求频率以及保证数据的唯一性和一致性,app侧也需要进行限制来避免产生垃圾数据 常用的方案有: 限制按钮的点击频率: 针对注册类接口的时间间隔...:withObject:afterDelay:实现 [self performSelector:@selector(resetState) withObject:nil afterDelay...self.isIgnoreEvent){ return; }else if (self.timeInterval > 0){ [self performSelector...:@selector(resetState) withObject:nil afterDelay:self.timeInterval]; } } //此处 methodA...https://github.com/zhangkn/simpleTools/blob/master/simpleTools/UIButton%2Btouch.h 1.3 使用和测试 使用:由于采用分类在UIButton
:@selector(startBaseAnimation) withObject:nil afterDelay:pauseDuration]; } } 这里有两个问题: CABasicAnimation...) withObject:nil afterDelay:pauseDuration]; 第一个问题要么在 viewWillDisappear 时,手动置该 delegate 为 nil,要么对该 view...:@selector(startBaseAnimation) withObject:nil afterDelay:pauseDuration]; } } 而什么时候为 NO 呢,顾名思义就是动画未完成...,所以动画正在执行中时,点击了返回按钮,回调的 flag 就为 NO,所以就不会执行 performSelector,所以也就不会造成内存泄露了。...我们 APP 里已经接入该库,在 Debug 模式中检测到类似的内存泄露就弹框或者 Assert,及时地发现和解决。 QQ音乐团队诚聘测试、研发。
1.performSelector – (void)performSelector:(SEL)aSelector withObject:(id)anArgument afterDelay:(NSTimeInterval...]; [selfperformSelectorOnMainThread:@selector(output:)withObject:@”main thread”waitUntilDone:YES]...3. sleep方式 [NSThread sleepForTimeInterval:1.0f]; [self delayMethod]; 此方式在主线程和子线程中均可执行。...是一种阻塞的执行方式,建方放到子线程中,以免卡住界面 没有找到取消执行的方法。...NSEC_PER_SEC)); dispatch_after(popTime, dispatch_get_main_queue(), ^(void){ [bself delayMethod]; }); 此方式在可以在参数中选择执行的线程
对于RunLoop而言最核心的事情就是保证线程在没有消息的时候休眠,在有消息时唤醒,以提高程序性能。RunLoop这个机制是依靠系统内核来完成的(苹果操作系统核心组件Darwin中的Mach)。...:@selector(test) withObject:nil afterDelay:10]; NSLog(@"3"); }); NSLog(@"4"); - (void)test {...原因是如果是带afterDelay的延时函数,会在内部创建一个 NSTimer,然后添加到当前线程的RunLoop中。也就是如果当前线程没有开启RunLoop,该方法会失效。...:@selector(test) withObject:nil afterDelay:10]; NSLog(@"3"); }); 然而test方法依然不执行。...:@selector(test) withObject:nil afterDelay:10]; [[NSRunLoop currentRunLoop] run]; NSLog
播放面板的曲线运动 使用核心动画中的 CAKeyframeAnimation 播放面板的变大缩小、控制面板消失出现 使用CABasicAnimation并加入组动画序列CAAnimationGroup中...self.startView.layer addAnimation:group forKey:nil]; self.layer.masksToBounds = YES; [self performSelector...:@selector(startViewBackAnimation) withObject:nil afterDelay:kAnimationDuration]; } 曲线动画 这里我们使用的是贝塞尔曲线...fillMode = kCAFillModeForwards; [self.startView.layer addAnimation:anmiation0 forKey:nil]; [self performSelector...:@selector(startViewChangeAnimation) withObject:nil afterDelay:1]; } 这里就要提到贝塞尔曲线的控制点了,这里有个简单的方法去定义曲线
– (void)initBlock{ //延时的方法 //1:GCD延时 此方式在能够在參数中选择运行的线程。 是一种非堵塞的运行方式,没有找到取消运行的方法。...cancelButtonTitle:@”确定” otherButtonTitles:@”取消”, nil]; ; }); //2:NSTimer延时,此方式要求必须在主线程中运行...scheduledTimerWithTimeInterval:8.0f target:self selector:@selector(delayMethod2) userInfo:nil repeats:NO]; //3:PerformSelector...延时 [self performSelector:@selector(delayMethod) withObject:nil afterDelay:5.0f]; //4:NSThread...]; } – (void)delayMethod{ UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@”” message:@”PerformSelector
preformSelector在delay 0秒时的执行顺序 - (void)mainMethod { [self performSelector:@selector(delayMethod...) withObject:nil afterDelay:1]; NSLog(@"调用方法==开始"); sleep(5); NSLog(@"调用方法==结束
时间 [self performSelector:@selector(stand) withObject:nil afterDelay:self.imageView.animationDuration...时间 [self performSelector:@selector(stand) withObject:nil afterDelay:self.imageView.animationDuration...就算指向它的指针被销毁,该资源也不会被从内存中干掉 b. 放到Assets.xcassets的图片,默认就有缓存 c. 图片经常被使用 2> imageWithContentsOfFile: a....指向它的指针被销毁,该资源会被从内存中干掉 b. 放到项目中的图片就不由缓存 c....1.在界面被加载时创建播放音乐器 //创建播放器 self.player = [[AVPlayer alloc] init]; 2.播放音乐 //播放 NSURL *url = [[NSBundle
领取专属 10元无门槛券
手把手带您无忧上云