gpt4 book ai didi

iphone - UIActionSheet 不是为按钮索引加载操作吗?

转载 作者:行者123 更新时间:2023-11-28 19:22:40 25 4
gpt4 key购买 nike

我已经设置了一些代码,以便在 UIActionSheet 上点击两个单独的按钮时,将有两个不同的操作。不幸的是,按下按钮时没有任何反应。 UIActionSheet 就像按下取消按钮一样卸载。

这是我的代码:

- (IBAction)saveFile:(id)sender {

UIActionSheet *saveFileSheet = [[[UIActionSheet alloc]
initWithTitle:@"iDHSB Download Centre"
delegate:nil
cancelButtonTitle:@"Cancel"
destructiveButtonTitle:nil
otherButtonTitles:@"Download File", @"Show My Files", nil]
autorelease];

[saveFileSheet showInView:webView];

}

-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{

NSLog(@"Action Sheet Button Pressed");

if(buttonIndex == 1) {
NSLog(@"Show My Files");

[self.window presentModalViewController:savedFiles animated:YES];

}

if(buttonIndex == 2){

NSLog(@"Saving File");

// Get the URL of the loaded ressource
NSURL *theResourcesURL = [[webView request] URL];
// Get the filename of the loaded ressource form the UIWebView's request URL
NSString *filename = [theResourcesURL lastPathComponent];
NSLog(@"Filename: %@", filename);
// Get the path to the App's Documents directory
NSString *docPath = [self documentsDirectoryPath];
// Combine the filename and the path to the documents dir into the full path
NSString *pathToDownloadTo = [NSString stringWithFormat:@"%@/%@", docPath, filename];


// Load the file from the remote server
NSData *tmp = [NSData dataWithContentsOfURL:theResourcesURL];
// Save the loaded data if loaded successfully
if (tmp != nil) {
NSError *error = nil;
// Write the contents of our tmp object into a file
[tmp writeToFile:pathToDownloadTo options:NSDataWritingAtomic error:&error];
if (error != nil) {
UIAlertView *filenameErrorAlert = [[UIAlertView alloc] initWithTitle:@"Error Saving" message:[NSString stringWithFormat:@"The file %@ could not be saved. Please try again.", filename] delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[filenameErrorAlert show];
[filenameErrorAlert release];

NSLog(@"Failed to save the file: %@", [error description]);
} else {
// Display an UIAlertView that shows the users we saved the file :)
UIAlertView *filenameAlert = [[UIAlertView alloc] initWithTitle:@"File saved" message:[NSString stringWithFormat:@"The file %@ has been saved.", filename] delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[filenameAlert show];
[filenameAlert release];
}
} else {

NSLog(@"Error, file could not be saved");

}
}

else

{

NSLog(@"Error, could not find button index!");

}
}

谢谢,

詹姆斯

最佳答案

您已将 UIActionSheet 委托(delegate)设置为 nil。在此上下文中,您希望将其设置为 self

关于iphone - UIActionSheet 不是为按钮索引加载操作吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7391433/

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