【发布时间】:2011-10-04 21:28:32
【问题描述】:
我有以下 zipfile 类,它执行我的 zip 文件的下载。我有一个与我的 zip 文件关联的文件名。我需要知道要传递给 viewcontroller 类的文件名。每当我尝试从不同的类中访问值时,它总是返回 null。我实际上想知道如何使用 ZipFile 中的 responseString 并在 ViewController 中使用它。
/ZipFile.m/
-(NSString *) downloadZipFile{
fileManager = [NSFileManager defaultManager];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
directoryPath = [paths objectAtIndex:0];
filePath = [NSString stringWithFormat:@"%@/ZipFiles.zip", directoryPath];
NSURL *url=[NSURL URLWithString:@"http://www.abc.com/id=123"];
NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
[request setURL:url];
[request setHTTPMethod:@"POST"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
NSError *error1;
urlData=[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error1];
[fileManager createFileAtPath:filePath contents:urlData attributes:nil];
[SSZipArchive unzipFileAtPath:filePath toDestination:directoryPath];
NSLog(@"Finished unzipping database");
Tab_Table_WinAppDelegate *appDelegate = [[[Tab_Table_WinAppDelegate alloc] init] autorelease];
[appDelegate loadingViewControllerDidFinish];
NSString *total = [self total]; // returns value here
return total;
}
- (NSString *)total {
NSString *responseString = [[NSString alloc] initWithData:urlData encoding:NSASCIIStringEncoding];
NSString *fileName = [response suggestedFilename];
NSLog(@"Value : %@", fileName);
return fileName;
}
/*ViewController.m*/
- (CGSize)imageSizeAtIndex:(NSUInteger)index {
CGSize size = CGSizeZero;
if (index < [self imageCount]) {
ZipFile *map = [[ZipFile alloc]init];
size.width = [[map total] floatValue]; // returns null here
[map release];
}
return size;
}
【问题讨论】:
标签: iphone objective-c nsurlconnection nsurl nsurlrequest