gpt4 book ai didi

ios - 在 UIView 中启动操作之前添加事件表/UI 警报对话框

转载 作者:塔克拉玛干 更新时间:2023-11-02 10:09:11 25 4
gpt4 key购买 nike

在我正在开发的应用程序中,我有一个 View ,每当用户将文档导入应用程序时,该 View 就会首先出现。我想要的是出现一个对话框(可以是 UIAlert 或事件表菜单),询问用户是否真的要导入该文件(是或取消)。我想知道如何在执行导入操作之前显示 UIAlert/Actionsheet 菜单,以及如何分配一个操作当用户点击是时要完成的操作或否,或“更改文件

出现的 View 称为 ProgressBarView.m/h。其中是这样的 viewdidload:

- (void)viewDidLoad
{
[super viewDidLoad];
self.progressBar.progressTintColor = [UIColor colorWithRed:153.0/255 green:0 blue:0 alpha:1.0];
self.progressBar.progress = 0.0;
/*progressValueLabel = [NSString stringWithFormat:@"%.0f%%", (self.progressBar.progress * 100)];*/

self.progressTimer = [NSTimer scheduledTimerWithTimeInterval:0.3f
target:self
selector:@selector(changeProgressValue)
userInfo:nil
repeats:YES];

}

当在 appdidFinishLaunchwith 选项中开始导入时,这将在应用委托(delegate)中调用:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSURL *url = (NSURL *)[launchOptions valueForKey:UIApplicationLaunchOptionsURLKey];
if (url != nil && [url isFileURL]) {
**[self handleImportURL:url];** // this is the function that handles the import
}

导入并调用progressView的函数如下:

- (void)handleImportURL:(NSURL *)url
{

// Show progress window
UIStoryboard * storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];

__block PVProgressViewController * progressController = [storyboard instantiateViewControllerWithIdentifier:@"kProgressViewController"];
self.window.rootViewController = progressController;

// 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;
});
});
}

最佳答案

您可以将您的 NSURL 定义为一个 ivar,并在适当的 clickedButtonAtIndex: 方法中调用您的 handleImportURL: 方法,如下所示:

@implementation AppDelegate{
NSURL *_importURL;
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
_importURL = (NSURL *)[launchOptions valueForKey:UIApplicationLaunchOptionsURLKey];
if (url != nil && [url isFileURL]) {
[self confirmImportAlert];
}
}

UIActionSheet:

- (void)confirmImportAlert {
UIActionSheet *myActionSheet = [[UIActionSheet alloc] initWithTitle:@"Your Title" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Yes", nil];
myActionSheet.delegate = self;
[myActionSheet showInView:self.window];
}

-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{
if(buttonIndex == 0){
//initiate import
[self handleImportURL:_importURL];
}
else{
//don't initiate import
}
}

UIAlertView:

- (void)confirmImportAlert {
UIAlertView *myAlertView = [[UIAlertView alloc] initWithTitle:@"Your Title" message:@"Your Message" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Yes", nil];
[myAlertView show];
}

- (void)alertView:(UIAlertView *)alert clickedButtonAtIndex:(NSInteger)buttonIndex{
if(buttonIndex == 0){
//initiate import
[self handleImportURL:_importURL];
}
else{
//don't initiate import
}
}

关于ios - 在 UIView 中启动操作之前添加事件表/UI 警报对话框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18253555/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com