我在我的项目中使用 MBPogressHUD,并且我已经正确设置了所有库、导入等。但是,我遇到了一个似乎与选择器方法有关的崩溃。我有一个名为“getInfo”的方法,它基本上连接到服务器。HUD 通过按下按钮触发。在对崩溃进行了一些研究之后,人们说将初始化放在 viewWillAppear 中,因为一些初始化时间占用了实际执行任务和显示 HUD 所需的时间。
    -(void)viewWillAppear:(BOOL)animated {
    connectionHUD = [[MBProgressHUD alloc]initWithView:self.view];
    [self.view addSubview:connectionHUD];
    connectionHUD.labelText = @"Connecting";
    connectionHUD.mode = MBProgressHUDModeAnnularDeterminate;    
}
-(IBAction)connectButton:(id)sender {
    [connectionHUD showWhileExecuting:@selector(getInfo) onTarget:self withObject:nil animated:YES];
}
碰撞:
Tried to obtain the web lock from a thread other than the main thread or the web thread. This may be a result of calling to UIKit from a secondary thread. Crashing now...
-(void)getInfo {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
UserPi *newPi = [[UserPi alloc]init];
newPi.passWord = self.passTextField.text;
[defaults setObject:self.passTextField.text forKey:@"password"];
newPi.userName = self.userTextField.text;
[defaults setObject:self.userTextField.text forKey:@"username"];
newPi.ipAddress = self.ipTextField.text;
[defaults setObject:self.ipTextField.text forKey:@"ip"];
[newPi connectToServer];
NSString* newAddress = [newPi returnIP];
self.connected = newPi.connected;
[self.delegate sendIP:newAddress];
[self.delegate isConnected:self.connected];
[defaults synchronize];
[self.navigationController popToRootViewControllerAnimated:YES];
}
完整错误:
bool _WebTryThreadLock(bool), 0x7327740: Tried to obtain the web lock from a thread other than the main thread or the web thread. This may be a result of calling to UIKit from a secondary thread. Crashing now...
1   0x3a1ffe9 WebThreadLock
2   0x4ec8ff -[UITextRangeImpl isEmpty]
3   0x4ec4db -[UITextRange(UITextInputAdditions) _isCaret]
4   0x48e7b6 -[UITextSelectionView setCaretBlinks:]
5   0x328f79 -[UIKeyboardImpl setCaretBlinks:]
6   0x3185bc -[UIKeyboardImpl setDelegate:force:]
7   0x3184ae -[UIKeyboardImpl setDelegate:]
8   0x53ff65 -[UIPeripheralHost(UIKitInternal) _reloadInputViewsForResponder:]
9   0x29215b -[UINavigationController navigationTransitionView:didStartTransition:]
10  0x418961 -[UINavigationTransitionView transition:fromView:toView:]
11  0x418658 -[UINavigationTransitionView transition:toView:]
12  0x294651 -[UINavigationController _startTransition:fromViewController:toViewController:]
13  0x29489b -[UINavigationController _startDeferredTransitionIfNeeded:]
14  0x295dc6 _popViewControllerNormal
15  0x296065 -[UINavigationController _popViewControllerWithTransition:allowPoppingLast:]
16  0xe6124b0 -[UINavigationControllerAccessibility(SafeCategory) _popViewControllerWithTransition:allowPoppingLast:]
17  0x2961a8 -[UINavigationController popViewControllerWithTransition:]
18  0x2965b9 -[UINavigationController popToViewController:transition:]
19  0x296257 -[UINavigationController popToRootViewControllerWithTransition:]
20  0x2961de -[UINavigationController popToRootViewControllerAnimated:]
21  0x4868 -[ConnectionViewController getInfo]
22  0x126a6b0 -[NSObject performSelector:withObject:]
23  0x8657 -[MBProgressHUD launchExecution]
24  0xca1805 -[NSThread main]
25  0xca1764 __NSThread__main__
26  0x95108ed9 _pthread_start
27  0x9510c6de thread_start