我还是 iOS 新手,在我正在开发的应用程序中,当用户从外部源导入文件时,会显示此视图。我希望仅在用户确认在操作表中执行导入后,层次结构如下:
用户从他的电子邮件中选择在应用程序中打开文件。
然后,他切换到progressView(在导入过程中以编程方式成为根视图)。
该过程完成并且默认的根视图被设置回来。
我想要的是询问用户是否真的想在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:所以我添加并更改了两种方法(我似乎无法在应用程序委托中调用 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;
}