我想显示一个简单的加载对话框,当我的应用程序发生某些事情时。我想我会创建一个新的视图,为其添加一个标签,然后将该视图设置为当前视图的子视图。iPhone:添加“加载”子视图
当这样做时,我什么都看不到!
这里是我怎么写我的方法:
- (void)showLoading {
UIView *loading = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 200, 200)];
loading.backgroundColor = [UIColor blackColor];
UILabel *txt = [[UILabel alloc] initWithFrame:CGRectMake(198, 9, 94, 27)];
txt.text = @"Loading...";
txt.textColor = [UIColor whiteColor];
[loading addSubview:txt];
[super.view addSubview:loading];
[super.view bringSubviewToFront:loading];
[loading release];
[txt release];
}
我这样做完全错了吗?
编辑: 我把它添加到viewDidLoad方法,它的作品我多么希望:
loading = [[UIView alloc] initWithFrame:CGRectMake(100, 100, 200, 200)];
loading.backgroundColor = [UIColor blackColor];
UILabel *txt = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 94, 27)];
txt.text = @"Loading...";
txt.textColor = [UIColor whiteColor];
[loading addSubview:txt];
[txt release];
[self.view addSubview:loading];
[self.view bringSubviewToFront:loading];
但是从方法加载的时候,它似乎滞后,并没有显示出来了一点。
我想在显示HUD时显示HUD,但由于某种原因,它会一直等待循环显示HUD。这是正常的吗? – 2010-08-16 02:37:17
这是一个正常的错误:试图从主线程或Web线程以外的线程获取Web锁。这可能是从辅助线程调用UIKit的结果。现在崩溃...? – 2010-08-16 02:56:43
通过在主线程中运行我的UI代码修复了错误。 – 2010-08-16 20:55:37