gpt4 book ai didi

objective-c - UIActivityIndi​​cator没有立即显示

转载 作者:行者123 更新时间:2023-12-01 19:15:33 24 4
gpt4 key购买 nike

由于某种原因,我无法立即显示 Activity 指示器。也许有人能明白为什么?

UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
spinner.center = self.view.center;
_active = spinner;
[self.view addSubview:spinner];
[spinner startAnimating];
@try {

[self connectToServerUsingStream:ip portNo:port];
NSString *text = @"test";
const uint8_t *str =
(uint8_t *) [text cStringUsingEncoding:NSASCIIStringEncoding];
[self writeToServer:str];

}
@catch (NSException * e) {
NSLog(@"Exception: %@", e);
}

微调框仅显示,然后与服务器建立连接,然后再不显示。有任何想法吗?

最佳答案

使用下面的更新代码。我认为它将起作用。

UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
spinner.center = self.view.center;
_active = spinner;
[self.view addSubview:spinner];
[spinner startAnimating];
[self performSelector:@selector(performTask) withObject:nil afterDelay:0.0];

- (void)performTask {
@try {
[self connectToServerUsingStream:ip portNo:port];
NSString *text = @"test";
const uint8_t *str =
(uint8_t *) [text cStringUsingEncoding:NSASCIIStringEncoding];
[self writeToServer:str];

}
@catch (NSException * e) {
NSLog(@"Exception: %@", e);
}
}

关于objective-c - UIActivityIndi​​cator没有立即显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13640326/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com