• perform系列  通知  timer等研究


    - (void)viewDidLoad
    {
        [super viewDidLoad];
        // Do any additional setup after loading the view, typically from a nib.
        //[self performSelectorInBackground:@selector(tt) withObject:nil];
    //    NSLog(@"%@",[NSThread currentThread]);
    //    NSLog(@"%d",[NSThread isMultiThreaded]);
    //    NSLog(@"%@",[NSThread mainThread]);
        
    //    [NSThread detachNewThreadSelector:@selector(tt:) toTarget:self withObject:@"yyyyy"];
    //    sleep(3);
    //    NSLog(@"----------");
        
        //[self performSelectorInBackground:@selector(read) withObject:nil];
        //[self performSelector:@selector(write:) withObject:@"aaaa" afterDelay:3.0];
        //NSDistributedNotificationCenter
        //[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(write:) name:@"ccc" object:nil];
        //_ob = [[myobject alloc] init];
        //_tt = [[[[thb alloc] init] autorelease] autorelease];
        
       
       
        //[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(write1:) name:@"ccc" object:nil];
    //    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(write2:) name:@"ccc" object:nil];
    //    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(write3:) name:@"ccc" object:nil];
    //    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(write4:) name:@"ccc" object:nil];
    //    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(write5:) name:@"ccc" object:nil]
    ;
        
    //    _queue = [[NSOperationQueue alloc] init];
    //    [[NSNotificationCenter defaultCenter] addObserverForName:@"ccc" object:nil queue:_queue usingBlock:^(NSNotification *note) {
    //        sleep(5);
    //        NSLog(@"%@",note);
    //    }];
        //NSLog(@"[NSRunLoop currentRunLoop] = %@",[NSRunLoop currentRunLoop]);
        
        //[NSTimer scheduledTimerWithTimeInterval:0 target:self selector:@selector(threadGo) userInfo:nil repeats:NO];
        
        //[[NSMyNotificationCenter defaultCenter] addObserver:self forKeyPath:@"parame" options:NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld context:nil];
        //[self performSelector:@selector(write1:) withObject:nil];
        //[_ob addObserver:self forKeyPath:@"pix" options:NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld context:nil];
        //NSLog(@"[_tt retainCount] = %d",[_tt retainCount]);
    //    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
    //        
    //    });
        //[NSThread detachNewThreadSelector:@selector(threadGo) toTarget:self withObject:nil];
        //_thread = [[NSThread alloc] init];
        //[_thread start];
    //    while (!_finished) {
    //        NSLog(@"runloop…");
    //        
    //        [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]];
    //        NSLog(@"runloop end.");
    //    }
       //NSLog(@"%@",[NSRunLoop mainRunLoop]);
        //[NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(write:) userInfo:nil repeats:YES];
        //[NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(write1:) userInfo:nil repeats:YES];
        
       

       

        
        
        //[self performSelector:@selector(write:) onThread:_thread withObject:nil waitUntilDone:YES];
        NSLog(@"77777777");
        //NSLog(@"NSNotificationQueue defaultQueue] = %@",[NSNotificationQueue defaultQueue]);
    }

    - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
        if ([keyPath isEqualToString:@"parame"]) {
            //sleep(3);
            NSLog(@"parame");
        }
        
        if ([keyPath isEqualToString:@"pix"]) {
            NSLog(@"pix");
        }
    }

    - (void)write:(id)par{
        //NSLog(@"par = %@",par);
        NSLog(@"go in");
         //NSLog(@"%@",[NSRunLoop currentRunLoop]);
        sleep(2);
        //label.text = [NSString stringWithFormat:@"%@",[NSDate date]];
        NSLog(@"go out");
        //SRunLoop *runloop = [NSRunLoop currentRunLoop];
        //NSTimer 对象不管调用哪个方法都不会重新创建一个新的线程,只会作为一个timer源添加到当前所在的runLoop,并让runloop执行它。并且timer的响应是同步的,如果其响应函数太耗时会阻塞runloop中后面事件的响应,比如在主线程中有这样的情况,那么在timer响应函数期间,会卡死界面,并阻止后面的事件响应 要排队
        //NSTimer *timer = [NSTimer timerWithTimeInterval:0 target:self selector:@selector(threadGo) userInfo:nil repeats:NO];
        //[runloop addTimer:timer forMode:NSDefaultRunLoopMode];
        
        //[runloop runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]];
        
        //NSLog(@"runloop = %@",runloop);
        //NSLog(@"%@",[NSString stringWithFormat:@"%@--%d",par.object,0]);
    }
    - (void)threadGo {
        @autoreleasepool {
           // NSLog(@"NSNotificationQueue defaultQueue]111 = %@",[NSNotificationQueue defaultQueue]);
             //NSNotification *no = [NSNotification notificationWithName:@"ccc" object:nil userInfo:nil];
            //[[NSNotificationQueue defaultQueue] enqueueNotification:no postingStyle:NSPostASAP];
            //[[NSNotificationCenter defaultCenter] postNotificationName:@"ccc" object:nil];
            
            [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(write1:) name:@"ccc" object:nil];
            NSLog(@"==============");
    //        NSTimer *timer = [NSTimer timerWithTimeInterval:1 target:self selector:@selector(write:) userInfo:nil repeats:YES];
    //       
    //        //[NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(write:) userInfo:nil repeats:YES];
    //        //while (!_finished) {
    //        //NSLog(@"runloop…");
    //        //_loop = [[NSRunLoop currentRunLoop] getCFRunLoop];
    //        [[NSRunLoop currentRunLoop] addTimer:timer forMode:NSDefaultRunLoopMode];
    //        [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]];
            NSLog(@"runloop end.");
            //}
        }
        
        //NSTimer *timer = [NSTimer timerWithTimeInterval:3 target:self selector:@selector(write1:) userInfo:nil repeats:YES];
        //CFRunLoopRef loop = CFRunLoopGetCurrent();
    //    CFRunLoopAddTimer(CFRunLoopGetCurrent(), CFRunLoopTimerCreate(
  • 相关阅读:
    文本框字数减少
    区分兼容IE6/IE7/IE8/IE9/FF的CSS HACK写法
    将浏览器兼容代码标明信息并相互分开
    JavaScript正则表达式
    CSS3 @font-face
    iOS 获取手机的使用存储信息
    升级 ox 10.11的系统以后执行 pod install 的时候报错
    Xcode7安装模拟器
    iOS-视图生命周期
    Xcode升级插件失效修复快捷方式
  • 原文地址:https://www.cnblogs.com/cnsec/p/11515804.html
Copyright © 2020-2023  润新知