我还是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]它不起作用。 –