iPhone - UIActivityIndicatorView 停止时不会隐藏
我有一个像这样编写的自定义 UIWebView :
.h
@interface MiniWebViewController : UIViewController {
NSString* destinationURL;
UIWebView* webView;
UIActivityIndicatorView* activityIndicatorView;
}
@property (nonatomic, retain) NSString* destinationURL;
@property (nonatomic, retain) IBOutlet UIWebView* webView;
@property (nonatomic, retain) IBOutlet UIActivityIndicatorView* activityIndicatorView;
- (void) run;
@end
.m
@synthesize destinationURL;
@synthesize webView;
@synthesize activityIndicatorView;
- (id) initWithFrame:(CGRect)frame {
if (self = [super initWithNibName:@"MiniWebView" bundle:nil]) {
self.destinationURL = @"";
self.view.frame = frame;
self.activityIndicatorView.center = self.webView.center;
}
return self;
}
- (void) run {
[self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:self.destinationURL]]];
}
它被称为从另一个 ViewController 启动:
- (void) aFunction {
MiniWebViewController* oneViewController = [[MiniWebViewController alloc] initWithFrame:CGRectMake(/*Some Rect*/];
oneViewController.webView.tag = i;
oneViewController.destinationURL = /*SomeURL*/;
oneViewController.webView.delegate = self;
[self.view addSubview:oneViewController.view]; /* the Web view is inside this one */
[oneViewController run];
}
- (void) webViewDidFinishLoad:(UIWebView *)webView {
int webViewID = webView.tag;
MiniWebViewController* webViewController = [self.webViews objectAtIndex:webViewID];
[webViewController.activityIndicatorView stopAnimating];
}
- (void)webViewDidStartLoad:(UIWebView *)webView {
int webViewID = webView.tag;
MiniWebViewController* webViewController = [self.webViews objectAtIndex:webViewID];
[webViewController.activityIndicatorView startAnimating];
}
还检查了 Into IB hidesWhenStopped 。一切都是相连的。 IB 中指标的样式设置为“大白色”。
运行时,指标不是大,而是小。
它已成功启动和停止(触发委托调用),但停止时不会隐藏。
有什么问题吗?我没看到...
I have a custom UIWebView written like this :
.h
@interface MiniWebViewController : UIViewController {
NSString* destinationURL;
UIWebView* webView;
UIActivityIndicatorView* activityIndicatorView;
}
@property (nonatomic, retain) NSString* destinationURL;
@property (nonatomic, retain) IBOutlet UIWebView* webView;
@property (nonatomic, retain) IBOutlet UIActivityIndicatorView* activityIndicatorView;
- (void) run;
@end
.m
@synthesize destinationURL;
@synthesize webView;
@synthesize activityIndicatorView;
- (id) initWithFrame:(CGRect)frame {
if (self = [super initWithNibName:@"MiniWebView" bundle:nil]) {
self.destinationURL = @"";
self.view.frame = frame;
self.activityIndicatorView.center = self.webView.center;
}
return self;
}
- (void) run {
[self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:self.destinationURL]]];
}
It is called an initied from another ViewController :
- (void) aFunction {
MiniWebViewController* oneViewController = [[MiniWebViewController alloc] initWithFrame:CGRectMake(/*Some Rect*/];
oneViewController.webView.tag = i;
oneViewController.destinationURL = /*SomeURL*/;
oneViewController.webView.delegate = self;
[self.view addSubview:oneViewController.view]; /* the Web view is inside this one */
[oneViewController run];
}
- (void) webViewDidFinishLoad:(UIWebView *)webView {
int webViewID = webView.tag;
MiniWebViewController* webViewController = [self.webViews objectAtIndex:webViewID];
[webViewController.activityIndicatorView stopAnimating];
}
- (void)webViewDidStartLoad:(UIWebView *)webView {
int webViewID = webView.tag;
MiniWebViewController* webViewController = [self.webViews objectAtIndex:webViewID];
[webViewController.activityIndicatorView startAnimating];
}
Into IB hidesWhenStopped is also checked. Everything is linked. The style of the indicator is set to "Large White" into IB.
When running, the indicator is not large, but small.
It is successfully started and stopped (delegate calls are triggered), but it doesn't hide when stopped.
What's the problem ? I don't see...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
仔细查看代码后,您将在
init
方法中修改 UIActivityView。更改它们,以便它们位于您的viewDidLoad
中。在初始化时,您的视图尚未加载,因此,控制器中尚未创建这些对象的实例。这些是需要移动的语句:
这可以追溯到 Objective-C 的基础:向
nil
对象发送消息...返回nil
。有时,这是一个烦人的功能,因为没有编译时警告,也没有任何运行时异常——这是该语言的一个功能。After a careful look in your code, you are modifying the UIActivityView in your
init
method. Change those so that they are in yourviewDidLoad
. At init, you view is not yet loaded, therefore, there is not an instance of those objects yet created in your controller.These are the statement that need to be moved:
This goes back to a fundamental of Objective-C: Sending a message to a
nil
object...returnsnil
. This is an annoying feature at times because there is no compile time warning, nor is there any runtime exception--a feature of the language.我很愚蠢,XCode/cocoa 确实没有帮助。
我加载了不存在的错误 XIB 名称。
所以我要求加载不存在的东西,应用程序仍然可以工作,甚至显示和使用不存在的对象。直到一个调用不能按预期工作。没有崩溃...
这是无稽之谈。
Stupid I am, and XCode/cocoa really doesn't help.
I had loaded a wrong XIB name that DOES NOT exist.
So I ask to load something that does not exist, and the app stil works, even showing and using objects that does not exist. Untill one call does not work as expected. No crash...
It's nonsense.