我還是iOS的新手,在我開發的應用程序中,當用戶從外部源導入文件時出現此視圖。我想有隻執行導入的用戶確認,在動作片, 的hiearchy如下之後:iOS:請求用戶通過ActionSheet確認發送調度隊列請求之前
用戶從他的電子郵件的動產在應用程序中打開該文件。
然後,他切換到progressView(在導入過程中編程方式成爲根視圖)。
該過程完成並且默認rootview被設置回。
我想是詢問用戶是否真的想盡快導入爲progressView表演,如果不是他要取消它(我不知道該怎麼做)
謝謝你,
下面是函數:
- (void)handleImportURL:(NSURL *)url
{
__block JASidePanelController * controller = (JASidePanelController *)self.window.rootViewController;
// Show progress window
UIStoryboard * storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
__block PVProgressViewController * progressController = [storyboard instantiateViewControllerWithIdentifier:@"kProgressViewController"];
self.window.rootViewController = progressController;
// I think here somethings needs to be done with UIActionsheet
// Perform import operation
dispatch_async(dispatch_get_global_queue(0, 0), ^{
NSError *outError;
NSString * csvString = [NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:&outError];
NSArray * array = [csvString csvRows];
[[PVDatabaseController sharedController] importArray:array progressHandler:^(float progress) {
progressController.progressBar.progress = progress;
}];
dispatch_async(dispatch_get_main_queue(), ^{
self.window.rootViewController = controller;
});
});
}
更新:所以這是我試圖用行動表做:
//First the function that calls the handleImport
-(BOOL) application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
// Handle CSV Import
if (url != nil && [url isFileURL]) {
[self handleImportURL:url];
[self confirmImportAlert];
}
return YES;
}
//要顯示動作片
- (void)confirmImportAlert {
UIActionSheet *myActionSheet = [[UIActionSheet alloc] initWithTitle:@"Proceed through Import?" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Yes", @"Maybe", nil];
[myActionSheet showInView: self.window];
}
// what to do
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{
if(buttonIndex == 0){
// Avoid Import
}
else{
[self handleImportURL:_importURL];
//initiate import
}
}
更新2:所以我添加和更改的兩種方法(I似乎無法調用應用程序代理的ActionSheetWilldismiss功能):
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{
NSString *choice = [ actionSheet buttonTitleAtIndex:buttonIndex];
if(buttonIndex == 0){
//initiate import
[self handleImportURL:_importURL];
}
else{
//don't initiate import
}
}
//This methods creats the action sheet
- (void)confirmImportAlert {
// importActionSheet is a property in the appdelegate.h
if (!self.importActionSheet){
UIActionSheet *myActionSheet = [[UIActionSheet alloc] initWithTitle:@"Proceed through Import?" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Yes", nil];
[myActionSheet showInView: self.window];
myActionSheet.delegate = self;
self.importActionSheet = myActionSheet;
}
}
並將調用導入的功能改爲:
-(BOOL) application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
// Handle CSV Import
if (url != nil && [url isFileURL]) {
[self confirmImportAlert];
//[self handleImportURL:url];
}
return YES;
}
你好,我做了一個嘗試(請參見上面)添加動作表,但是如果我刪除OpenUrl函數中的[self handleImportURL:url]它不起作用。 –