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]);