-2
-(void)startConnection
{ 
    NSString *urlString = GET_EVENTLIST_URL_STRING;

    NSURL *url = [NSURL URLWithString:[urlString stringByAddingPercentEscapesUsingEncoding:NSISOLatin1StringEncoding]];
    [urlString UTF8String];


    if (!url)
    {
        NSString *reason = [NSString stringWithFormat:@"Could not create URL from string %@", GET_EVENTLIST_URL_STRING];
        [self.delegate didGetEventListInCorrect:reason];
        return;
    }

    theRequest = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval: 30.0];

    // Set the HTTP method of the request to POST
    [theRequest setHTTPMethod:@"POST"];

    [theRequest setHTTPBody:[urlString dataUsingEncoding:NSUTF16StringEncoding]];



    if (!theRequest)
    {
        NSString *reason = [NSString stringWithFormat:@"Could not create URL request from string %@", GET_EVENTLIST_URL_STRING];
        [self.delegate didGetEventListInCorrect:reason];
        return;
    }
    theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];

    if (!theConnection)
    {
        NSString *reason = [NSString stringWithFormat:@"URL connection failed for string %@", GET_EVENTLIST_URL_STRING];
        [self.delegate didGetEventListInCorrect:reason];
        return;
    }

    if (theConnection)
    {
        myData = [[NSMutableData alloc]init];

    }

}

#pragma mark - Methods connection
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)aResponse
{
    // receivedData is an instance variable declared elsewhere.
    [myData setLength:0];
}

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)theData
{
    // Append the new data to receivedData.
    // receivedData is an instance variable declared elsewhere.
    [myData appendData:theData];
}

- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
    // finished downloading the data, cleaning up
    [self.delegate didGetEventListCorrect:myData ];
}

- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
    [self.delegate didGetEventListInCorrect:@"Failed Connection"];
}

#pragma mark - Main method of LoginUrlConnection with NSURLRequest and NSURLConnection
+ (id) connectionGetEventList:(id<GetEventListURLConnectionDelegate>)aDelegate
{
    EventListURLConnection *getEventListUrlConnection = [[self alloc]init];

    getEventListUrlConnection.delegate = aDelegate;

    [getEventListUrlConnection startConnection];

    return getEventListUrlConnection;
}

こんにちは、これは URL 接続用の私のクラスで、ビュー コントローラーでこのリストを次のように呼び出しています: " eventconnection = [EventListURLConnection connectionGetEventList:self]; " http://www.google.com.tr/imgres?hl=ja&sa=X&tbo=d&biw=1063&bih=502&tbm=isch&tbnid=3fZwJc8SC_xoPM:&imgrefurl=http://www.hongkiat.com/blog/most-wanted-freebies- web-designers/&docid=VLaTiYV3nRfeXM&imgurl=http://media02.hongkiat.com/freebies-for-web-designers-2011/progress-bar.jpg&w=580&h=250&ei=jxnrUMWpOKb24QTn54CQCg&zoom=1&iact=hc&vpx=698&vpy=185&dur=704 148&hovw=342&tx=162&ty=102&sig=114441653047551513554&page=2&tbnh=147&tbnw=319&start=16&ndsp=14&ved=1t:429,r:19,s:0,i:142 "..どうすればこれを管理できますか?何かアイデアはありますか?事前に感謝します..

4

1 に答える 1

1

UISlider を使用して、読み込みの進行状況を追跡できます。したがって、コンテンツを保持するために myData を使用すると仮定すると、FILE_SIZE はダウンロードするコンテンツのバイト単位のサイズであり、progressView は UISlider です (実際には、UISlider サブビューとダウンロードされた % を指定する UILabel サブビューを含むカスタム ビューにすることもできます)。 )、次のコードスニペットでそれを行う必要があります...

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
    [self.myData appendData:data];
    float percentDownloaded = (float)[self.myData length]/FILE_SIZE;
    NSLog (@"PERCENT DOWNLOADED IS %d %f : %f",[self.myData length], percentDownloaded,percentDownloaded*100);
    [self.progressView setProgress:percentDownloaded];

}
于 2013-01-07T19:15:31.103 に答える