我有以下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;
}
答案 0 :(得分:0)
ZipFile *map = [[ZipFile alloc]init];
这会创建一个新的ZipFile,这可能不是你想要做的。你需要一些方法将你真正感兴趣的ZipFile对象传递给控制器。