पर NSURLConnection लोडिंग प्रक्रिया जोड़ें मैंने UIProgressView
बनाया है। लेकिन मैंने NSTimer
UIProgressView's
प्रक्रिया का उपयोग किया। यूआरएल लोड होने पर अब मुझे UIProgressView
प्रक्रिया को एकीकृत करने की आवश्यकता है। UIProgressView's
आकार NSURLConnection's
डेटा पर निर्भर करेगा।UIProgressView
मैंने निम्नलिखित कोड NSURLConnection
पर उपयोग किया। _totalFileSize = response.expectedContentLength;
:
-(void)load {
NSURL *myURL = [NSURL URLWithString:@"http://feeds.epicurious.com/newrecipes"];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:myURL
cachePolicy:NSURLRequestReloadIgnoringLocalCacheData
timeoutInterval:60];
[[NSURLConnection alloc] initWithRequest:request delegate:self];
}
-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
responseData = [[NSMutableData alloc] init];
}
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
[responseData appendData:data];
}
-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
[connection release];
UIAlertView *alert = [[UIAlertView alloc] init];
[alert setTitle:@"Warning"];
[alert setMessage:@"Network Connection Failed?"];
[alert setDelegate:self];
[alert addButtonWithTitle:@"Yes"];
[alert show];
[alert release];
NSLog(@"Error");
}
-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
responsetext = [[[NSString alloc] initWithData:responseData encoding: NSASCIIStringEncoding] autorelease];
}
कैसे didReceiveResponse में प्रतिक्रिया घोषित करने के लिए, कृपया निम्न कोड को संपादित प्रतिनिधियों को लागू कर सकता है। - (शून्य) कनेक्शन: (NSURLConnection *) कनेक्शन didReceiveData: (NSData *) डेटा { \t कुल FileSize = response.expectedContentLength; \t प्राप्तडेटाइट्स + = [डेटा लंबाई]; \t एनएसएलओजी (@ "कुलफाइल आकार/कुलफाइल आकार =% एफ", प्राप्तडेटाइट्स/कुलफाइल आकार); \t [प्रतिक्रिया डेटा संलग्न करें डेटा: डेटा]; } – Velmurugan
didReceiveResponse और didReceiveData 2 अलग-अलग प्रतिनिधि हैं। यह होना चाहिए: - (शून्य) कनेक्शन: (NSURLConnection *) कनेक्शन didReceiveResponse: (NSURLResponse *) प्रतिक्रिया { कुल FileSize = response.expectedContentLength; } और उस रेखा को हटा दें ReeceiveData – Hless
मेरा उत्तर संपादित करें। मैं यह उल्लेख करना भूल गया था कि आपके द्वारा विभाजित मूल्यों में से एक को एक फ्लोट पर डाला जाना चाहिए। चूंकि आप फ्लोट परिशुद्धता के बिना अन्यथा पूर्णांक के साथ समाप्त हो सकते हैं। – Hless