简体   繁体   English

如何实现多个下载代码目标

[英]How to implement multiple download code objective c

Im sorry, i feel kind of dumb, but im having trouble implementing the following code for to download multiple files from the server.I have set up the MultipleDownload.h and MultipleDownload.m files as a new Objective-C class within my app. 很抱歉,我有点愚蠢,但无法执行以下代码从服务器下载多个文件。我已在我的应用程序中将MultipleDownload.h和MultipleDownload.m文件设置为新的Objective-C类。 But not sure how call it from my updateView.m to perfrom the file downloads. 但是不确定如何从我的updateView.m调用它来执行文件下载。 As per instructions it says i need to initialize and start downloading with the following lines. 按照说明,我需要初始化并使用以下代码行开始下载。 I cant figure out where to put that code to start downloading files from urls. 我想不通将代码放在哪里开始从url下载文件。 Do i have to setup a method within that MultipleDownload.m code and call that method it from another object (updateView.m) to initiate the download? 我是否必须在MultipleDownload.m代码中设置一个方法,然后从另一个对象(updateView.m)调用该方法以启动下载? or i do i put those lines into one of the methods in (updateView.m)? 还是我将这些行放入(updateView.m)中的方法之一? I honestly tried both and for some reason i keep getting errors, It says that urls. 老实说,我都尝试过,由于某种原因我一直出错,它说的是网址。 If i put it in updateView.m it says that self.urls and self.downloads is undeclared identifier. 如果我将其放在updateView.m中,则表示self.urls和self.downloads是未声明的标识符。 I tried to declare NSMutableArray *urls and MultipleDownload *downloads within my updateView.m and it doesnt seen to work either. 我试图在我的updateView.m中声明NSMutableArray * urls和MultipleDownload * downloads,但它也不起作用。 Any input would be appreciated. 任何输入将不胜感激。

the MultipleDownload.m and MultipleDownload.h code is located on github: http://github.com/leonho/iphone-libs/tree/master MultipleDownload.m和MultipleDownload.h代码位于github: http : //github.com/leonho/iphone-libs/tree/master

To initialize and start the download: 要初始化并开始下载:

self.urls = [NSMutableArray arrayWithObjects:
    @"http://maps.google.com/maps/geo?output=json&q=Lai+Chi+Kok,Hong+Kong", 
    @"http://maps.google.com/maps/geo?output=json&q=Central,Hong+Kong",
    @"http://maps.google.com/maps/geo?output=json&q=Wan+Chai,Hong+Kong", 
    nil];  
self.downloads = [[MultipleDownload alloc] initWithUrls: urls]; 
self.downloads.delegate = self; 

What you do is in updateView.h 您要做的是在updateView.h中

create @properties for urls (type NSMutableArray) and downloads (type MultiDownload) 为网址(类型为NSMutableArray)和下载(类型为MultiDownload)创建@properties

then in updateView.m you add a these functions 然后在updateView.m添加这些功能

//Function to start download
- (void) startDownload
{
    self.urls = [NSMutableArray arrayWithObjects:
                 @"YourURLS",
                 @"YourURLS",
                 @"YourURLS",
                 nil];
    self.downloads = [[MultipleDownload alloc] initWithUrls: urls];
    self.downloads.delegate = self;
}

 //download finished for 1 item
 - (void) didFinishDownload:(NSNumber*)idx {
    NSLog(@"%d download: %@", [idx intValue], [downloads dataAsStringAtIndex: [idx intValue]]);
 }

 //download finished for all items
 - (void) didFinishAllDownload {
    NSLog(@"Finished all download!");
    [downloads release];
 }

I also suggest that if you have problem understanding self.urls and self.downloads to read some more info about objective c and properties, good luck 我还建议,如果您在理解self.urls和self.downloads时遇到问题,以阅读有关目标c和属性的更多信息,祝您好运

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM