我试图让带有 ActivityIndicator 的 Loading UIAlertView 在我点击按钮后立即弹出。在那一刻,我需要它来运行dpkg命令。
我非常接近完成它。只有一个问题,当我触摸我的按钮时,当应用程序安装 debian 包时,UIAlertView 不会一直加载(屏幕变暗)。包安装完成后,UIAlertView 会一直加载一秒钟。然后被解雇[alert dismissWithClickedButtonIndex:0 animated:YES];
我不确定这是否需要在另一个线程上,所以我尝试这样做。不确定我是否设置正确。所以这是我的代码。建议?更正?
.m
-(IBAction)installdeb:(id)sender{
UIAlertView *alerty = [[UIAlertView alloc] initWithTitle:@"Installing..." message:nil delegate:nil cancelButtonTitle:nil otherButtonTitles: nil];
UIActivityIndicatorView *progress= [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(125, 50, 30, 30)];
progress.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge;
[alerty addSubview:progress];
[progress startAnimating];
[alerty show];
[alerty release];
[NSThread detachNewThreadSelector:@selector(installdeb) toTarget:self withObject:nil];
}
- (void)installdeb{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
char *installdebchar = [[NSString stringWithString:@"dpkg -i /Applications/MyApp.app/package.deb"] UTF8String];
system(installdebchar);
if (system(installdebchar) == 0){
[alerty dismissWithClickedButtonIndex:0 animated:YES];
UIImage *img1 = [UIImage imageNamed:@"whitecheckmark.png"];
[ImageView1 setImage:img1];
} else {
[alerty dismissWithClickedButtonIndex:0 animated:YES];
}
[pool release];
}
。H
@class DebInstallViewController;
@interface DebInstallViewController : UIViewController <UINavigationBarDelegate, UINavigationControllerDelegate, UIAlertViewDelegate>{
IBOutlet UIAlertView *alert;
IBOutlet UIImageView *ImageView1;
}
- (IBAction)installdeb:(id)sender;
@end
我对目标c有点陌生。所以不要恨。:) 建议?