开发者

Manage download progress in Objective-C

Good evening all, i'm at my first serious experience with Objective-c and i ask you a tip.

I Implement NSUrlConnetion delegate and i call this class from a principal viewController, for example name myViewController.

I want to see progress of download in viewController and i'm thinking to do semothing like this: in h file : ...interface myViewController where protocol receiveDelegate contains a method like -(int)setProgressPercent that return the percent of downloaded part. In .m file i call NSUrlDelegate passing self.

Then in NSUrlConnection delegate: in .h file: @property(nonatomic, retain) id father; and when i receviece something: [开发者_开发百科father setProgressPercent:newValue];

is all right for you?


The NSURLConnection's delegate will be sent connection:didReceiveData: every time data arrives. You will presumably accumulate this data into an NSMutableData instance variable. You can thus get the size of the NSMutableData accumulated thus far, and compare it to the full size of the object being downloaded and use that value to set something in your interface (presumably a progress indicator).

However, in order to do that, you must know in advance how big the full size of the object being downloaded will be. You may be able to learn this by parsing the NSURLResponse received by connection:didReceiveResponse:.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜