我正在尝试创建一个登录页面,在尝试时显示等待页面。它UIActivityIndicatorView
在主线程上运行,另一个线程在进行连接。当我取消注释时代码工作正常,但当我注释掉NSLog
它时它会继续运行。谁能向我解释为什么没有 while 循环时它不存在NSLog
?这有点复杂。我有一个控制类来准备websocket
命令并在且仅当websocket
成功连接时才触发它。
动作流程是这样的:
LoginButton
单击 -> rootView
呼叫[_spinner startAnimating];
-> 尝试连接websocket
-> 成功连接后发送登录命令。
rootView
必须为微调器设置动画并等待响应。
[_spinner startAnimating];
[NSThread detachNewThreadSelector:@selector(attampingWS) toTarget:self withObject:nil];
- (void) attampingWS {
while ([connection isAttamptingWS] && ![connection isConnectedToWebSocket]) {
/** waiting until it's done **/
// NSLog(@"?");
}
if ([connection isConnectedToWebSocket]) {
[self proceedLogin];
[_spinner performSelectorOnMainThread:@selector(stopAnimating) withObject:nil waitUntilDone:NO];
}
}
在连接类中:
@property(nonatomic) NSTimer *attampConnectionTimeOut;
@property(nonatomic) NSTimer *attampConnection;
@property BOOL isConnectedToWebSocket;
- (BOOL) isAttamptingWS {
return [_attampConnection isValid];
}
- (BOOL) isWaitingForResponse {
return [_waitingForResponse isValid];
}
/** this method is redirected from websocket by using delegation **/
- (void)dbConnectionDidConnected:(websocket *)connection {
[self _terminateAttamptingConnection];
[self setIsConnectedToWebSocket:TRUE];
}