【发布时间】:2011-11-24 23:51:40
【问题描述】:
我使用 NSThread 在单独的线程上创建一个对象。
NSThread* myThread = [[[NSThread alloc] initWithTarget:self selector:@selector(createNewObject:) object:elements] autorelease];
[myThread start]; // Actually start the thread
那个对象等待一个事件。当该事件发生时,会在默认通知中心发布通知。
我的 AppController 观察到该通知并运行一个选择器。
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
[nc addObserver:self selector:@selector(myMethod:) name:MyNotification object:nil];
问题: 选择器中的方法 (myMethod:) 是在主线程上运行还是在上面的线程上运行 (myThread) ?
【问题讨论】:
标签: objective-c cocoa delegates nsthread nsnotification