添加子视图,会延迟吗? [英] Adding subview, gets delayed?

查看:71
本文介绍了添加子视图,会延迟吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我真的不知道如何为这个问题加上标题,但这确实使我丧命: 在我的应用程序中,我有一个UITableView,UISegmentedControl和UINavigationBar.一旦UISegmentedControl获得其细分之一的选择,我想在UINavigationBar上显示一个UIActivityIndi​​catorView,然后解析一个xml文件并将结果显示在表中. 一切都按我想要的方式工作,除了一件事,活动指示器视图在解析器完成后被添加到uinavigationbar中,即使将UIIndicatorView添加到UINavigationBar的showLoading方法在解析器初始化之前即可获取. 有人可以解释吗?有什么我可能会想念的东西吗?也许用户界面需要重绘? 谢谢 彼得

i didn't really know how to title this question, but here's a thing that really kills me: In my app i have a UITableView, UISegmentedControl and UINavigationBar. Once UISegmentedControl gets one of its segments selected i want to show a UIActivityIndicatorView on the UINavigationBar and then parse an xml file and present the results in a table. Everything works almost as i want it to, except one thing, the activity indicator view gets added to the uinavigationbar after the parser finishes, even though the method showLoading that adds UIIndicatorView to UINavigationBar gets before parser is initialised. Can anyone explain it? is there something i might be missing? maybe the ui needs to get redrawn? thanks peter

推荐答案

看起来您在主线程中解析了xml,因此它因UI更改而被阻止.尝试将xml解析移至单独的线程(例如,通过-performSelectorInBackground:调用解析方法)

It looks that you parse your xml in main thread and so it becomes blocked for UI changes. Try to move xml parsing to separate thread (e.g. by calling your parsing method via -performSelectorInBackground:)

编辑:实际上,(几乎可以肯定)您在应用程序中隐式使用了autorelease-许多标准函数都返回自动释放的对象.在单独的线程上运行函数时,需要在其中创建NSAutoreleasePool对象以处理自动释放的对象并避免内存泄漏(请参阅

Actually you're (almost certainly) using autorelease implicitly in your application - as many standard functions return autoreleased objects. When you're running your functions on separate thread you need to create NSAutoreleasePool object there to handle autoreleased objects and avoid memory leaks (see Autorelease Pools in docs). So your parseXML function must look like:

- (void)parseXML{
   NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
   ... //xml parsing routines etc
   [pool release];
}

这篇关于添加子视图,会延迟吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆