【发布时间】:2011-12-25 19:23:48
【问题描述】:
有一个任务需要在一个 NSView 上绘制 N 个图像。 但是一开始我不知道图片的数量,所以我设置它在后台线程中工作。
[NSThread detachNewThreadSelector:@selector(workInBackgroundThread:) toTarget:self withObject:nil];
当它获得图片数量时,它会发送通知
- (void)workInBackgroundThread:(id)unusedObject {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
//get image amount....
[[NSNotificationCenter defaultCenter] postNotificationName:@"gotImageAmount" object:nil];
//...
//continue to load images
}
我尝试调整 NSView 的大小取决于通知功能中的图像数量
-(void)processGotImagesAmount:(NSNotification*)notification
{
//others codes
[myNSView setFrame:CGRectMake(0, 0, calculateNewWidth, caculatedNewHeight)];//line A
//others codes
}
但当应用程序执行 A 行时,它会冻结,
[myNSView setFrame:CGRectMake(0, 0, calculateNewWidth, caculatedNewHeight)];
本身没有问题,如果我点击一个bottun调用它,它就可以了!
但它似乎在通知功能中不起作用
欢迎评论
【问题讨论】:
标签: multithreading cocoa nsnotificationcenter