【发布时间】:2013-04-17 06:42:55
【问题描述】:
我正在使用线程调用我的函数“initialGetMethod”
[NSThread detachNewThreadSelector:@selector(initialGetMethod) toTarget:self withObject:nil];
我的get方法是
-(void) initialGetMethod
{
self.loginPassword = [[ UIAlertView alloc] initWithTitle:@"Please Login to MFP" message:@"Enter Valid UserID and Password" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:@"Cancel", nil];
[self.loginPassword setAlertViewStyle:UIAlertViewStyleLoginAndPasswordInput];
[self.loginPassword setTag:2];
[self.loginPassword show];
}
但它给出了异常“试图从主线程或网络线程以外的线程获取网络锁。这可能是从辅助线程调用 UIKit 的结果。”
它在“[self.loginPassword setAlertViewStyle:UIAlertViewStyleLoginAndPasswordInput];”处给出异常
如果我将该函数称为“[self initialGetMethod];”它没有给出例外,但需要一些时间..
我尝试在后台加载,但它不工作..(意味着我不希望它在后台)..
请提出一些解决方案..
【问题讨论】:
-
您无法在后台线程上执行 UI 操作,您为什么要这样做?
-
为什么用 iPhone-sdk-4.0 标记?我希望您不要尝试支持 iOS 4.0。
-
我尝试使用“[NSThread detachNewThreadSelector:@selector(initialGetMethod) toTarget:self withObject:nil];”但仍然得到同样的例外..
-
不...我使用的是 iOS 4.3..
标签: ios objective-c nsthread