Как получить доступ к NSURLResponse в другом классе - PullRequest
0 голосов
/ 14 июля 2011

У меня следующий класс zipfile, который выполняет загрузку моего zip-файла.У меня есть имя файла, связанное с моим zip-файлом.Мне нужно знать имя файла для передачи классу viewcontroller.Всякий раз, когда я пытаюсь получить доступ к значению из другого класса, он всегда возвращает мне ноль.Я действительно хочу знать, как я могу использовать responseString из ZipFile и использовать его в 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;
 }

1 Ответ

0 голосов
/ 14 июля 2011
    ZipFile *map = [[ZipFile alloc]init];

Это создает новый ZipFile, что, вероятно, не то, что вы хотите сделать. Вам понадобится какой-то способ передать интересующий вас объект ZipFile в контроллер.

...