我试图用ActivityIndicator加载UIAlertView,当我点击一个按钮时弹出。在那一刻,我需要它运行dpkg命令。如何为系统命令显示“加载UIAlertView”?
我非常接近完成它。只有一个问题,当我触摸我的按钮时,UIAlertView不会在应用程序安装debian软件包时全部加载(灰色屏幕)。只要包装完成安装,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。所以不要讨厌。 :)建议?