Iphone 当我添加活动指示器时,应用程序崩溃

Iphone 当我添加活动指示器时,应用程序崩溃,iphone,objective-c,xcode,Iphone,Objective C,Xcode,我正在编写一个应用程序,并在该应用程序中找到一个Web视图,我想添加一个活动指示器。所以我使用这个代码: timer = [NSTimer scheduledTimerWithTimeInterval:(1.0/2.0) target:self selector:@selector(loadingPage) userInfo:nil repeats:YES]; 但当我插入此代码时,我的应用程序崩溃并引用此代码: timer = [NSTimer scheduledTimer

我正在编写一个应用程序,并在该应用程序中找到一个Web视图,我想添加一个活动指示器。所以我使用这个代码:

timer = [NSTimer scheduledTimerWithTimeInterval:(1.0/2.0) 
         target:self selector:@selector(loadingPage) userInfo:nil repeats:YES];
但当我插入此代码时,我的应用程序崩溃并引用此代码:

timer = [NSTimer scheduledTimerWithTimeInterval:(1.0/2.0) 
         target:self selector:@selector(loadingPage) userInfo:nil repeats:YES];
main.m

#import <UIKit/UIKit.h>

int main(int argc, char *argv[])
{
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    int retVal = UIApplicationMain(argc, argv, nil, nil);
    [pool release];
    return retVal;
}
.m文件

[faktaPDF addSubview:pageLoadingIndicator];

[faktaPDF loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"Website"]]];

timer = [NSTimer scheduledTimerWithTimeInterval:(1.0/2.0) target:self selector:@selector(loadingPage) userInfo:nil repeats:YES];

如果活动指示器指的是一个旋转的轮子(称为UIActivityIndicatorView),则不需要计时器。它自己生动活泼;您只需将其放在视图上并调用[startAnimating]。

不要为此使用NSTimer,这太糟糕了。将自己指定为UIWebView的代表并实施

-webViewDidStartLoad:
以显示“加载视图”,然后实现


-webView:didFinishLoad:
-webView:didFailLoadWithError:
隐藏您的“loadingView”。

我在您的代码中没有看到任何活动指示器的引用,并且您的崩溃没有在main中发生。仔细观察控制台。此外,围绕NSTimer代码编写更多代码可能会很有用。还有loadingPage方法。你需要发布更多的代码,很可能你正在过度删除某些内容(或没有保留某些内容)…这通常是你的计时器。你应该发布loadingPage方法的代码。