gpt4 book ai didi

iphone - 如何显示指标

转载 作者:行者123 更新时间:2023-12-03 18:06:27 25 4
gpt4 key购买 nike

我无法显示指标 View 。

ItemController.h

#import <UIKit/UIKit.h>


@interface ItemController : UITableViewController {
UIView* loadingView;
UIActivityIndicatorView* indicator;
}

@property (nonatomic, retain) UIView *loadingView;
@property (nonatomic, retain) UIActivityIndicatorView *indicator;

@end

ItemController.m

.....
- (void)netAccessStart {


loadingView = [[UIView alloc] initWithFrame:[[self view] bounds]];
[loadingView setBackgroundColor:[UIColor blackColor]];
[loadingView setAlpha:0.5];
indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
[[self view] addSubview:loadingView];
[loadingView addSubview:indicator];
[indicator setFrame:CGRectMake ((320/2)-20, (480/2)-60, 40, 40)];
[indicator startAnimating];

}

- (void)netAccessEnd {


[indicator stopAnimating];
[loadingView removeFromSuperview];

}

- (void)dealloc {
[loadingView release];
[indicator release];
[super dealloc];
}
.....

继承类

- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self netAccessStart];
sleep(1);
[self netAccessEnd];
}

最佳答案

sleep() 阻止执行,这意味着您的应用在 -viewWillAppear 调用上卡住,在调用结束时您的 loadingView 得到从其 super View 中删除。换句话说,[self netAccessStart];[self netAccessEnd]; 之间不会发生任何绘制。我假设您为了测试目的而立即调用一个,在这种情况下,我会将 -netAccessStart 命令移至 -viewDidAppear: 并替换 >sleep/-netAccessEnd 调用如下:

[self performSelector:@selector(netAccessEnd) withObject:nil afterDelay:1];

...这将具有相同的效果,但不会阻止执行。

关于iphone - 如何显示指标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1736401/

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