我試圖用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。所以不要討厭。 :)建議?