NSBundle 中的 NSTask
我正在计算特定路径上的文件总数,并在 自定义单元格。 我正在使用 NSThread 来计算 - (void)drawWithFrame:(NSRect)cellFrame inView:(NSView*)controlView
(在包内)方法中的文件计数。当我计算文件计数时,它显示空单元格。我认为它在 NSThread
返回结果之前调用 [super drawWithFrame:newFrame inView:controlView];
。
有人可以帮我吗?谢谢 :)
I am calculating total number of file on particular path and showing that result in custom cell.
I am using NSThread for calculating file count in - (void)drawWithFrame:(NSRect)cellFrame inView:(NSView*)controlView
(inside the bundle) method. when i am calculating file count, its showing empty cell. i think its calling [super drawWithFrame:newFrame inView:controlView];
before NSThread
return the result.
Can anyone please help me out ?? Thanks :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为此使用线程的根本原因是不阻塞主线程上的 UI。有效的原因是线程启动,然后线程创建方法立即返回,以便主线程可以继续处理其他事务。
所以是的,您可以在线程完成之前到达 [super drawWithFrame:inView:]。您不应该等待线程完成——这会违背使用线程的目的。
不管怎样,你不应该在牢房里做这一切。您应该从表视图的数据源执行此操作。在获得目录列表后不久就开始您的线程(或者可能更好,操作),并在结果出现时更新单元格。
The very reason to use a thread for this is to not block the UI on the main thread. The reason that works is that is that the thread starts, and the thread-creation method then returns immediately so the main thread can get on with other business.
So yes, you get to
[super drawWithFrame:inView:]
before the thread has finished. You're not supposed to wait for the thread to finish—that would defeat the purpose of using a thread.You shouldn't be doing all this from the cell, anyway. You should be doing it from the table view's data source. Kick off your thread(s) (or, probably better, operations) shortly after you have your list of directories, and update the cells as the results come in.