【发布时间】:2010-09-20 05:47:59
【问题描述】:
我需要在后台显示一个计时器,用于以分钟:秒格式的 webrequest 加载时间。当 webrequest 成功加载时,计时器必须停止。我的代码在这里:
@interface TimerWithWebrequestViewController : UIViewController {
IBOutlet UIWebView *webView;
IBOutlet UILabel *lbl;
int mainInt;
NSTimer *randomMain;
}
@property(nonatomic,retain) UIWebView *webView;
-(void)upDate;
@end
@implementation TimerWithWebrequestViewController
@synthesize webView;
-(void)viewDidLoad
{
NSString *urlAdd = @"http://www.google.com";
NSURL *url = [NSURL URLWithString:urlAdd];
NSURLRequest *reqObj = [NSURLRequest requestWithURL:url];
[webView loadRequest:reqObj];
[self performSelectorInBackground:@selector (upDate) withObject:nil];
}
-(void)upDate
{
mainInt = 0;
randomMain = [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(randomMainVoid) userInfo:nil repeats:YES];
}
-(void)randomMainVoid{
mainInt += 1;
lbl.text = [NSString stringWithFormat:@"%d",mainInt];
}
【问题讨论】:
-
不要在 Stack Overflow 上使用“代码”标签。改用“101010”按钮格式化代码。
标签: iphone uiwebview ios nstimer