-1

こんにちはUITableView。これは、Web サービスから numberof データをロードします。このテーブルビューを 10 つずつロードしたいのですが、最初は最初の 10 項目をロードします。ユーザーが最後までスクロールするとUITableView、サーバーから次の 10 件のレコードが読み込まれます。だから私のscrollviewDidEndDeclaratingデリゲートで私はこのように置きます

`

 if (scrollView.tag==24) {


    [self performSelector:@selector(loadingalbumsongs:) withObject:nil afterDelay:0.1];
}`

しかし、問題は、スクロールを停止すると、テーブルビューがロードされるまで動かなくなることです。誰でも私にこれの解決策を教えてもらえますか

ありがとう

4

2 に答える 2

0

非同期Webサービスを呼び出すのに役立つNSURLCONNECTIONを試してください

NSURLConnection オブジェクトは、HTTP を使用して Web サービスを実行するために使用されます。NSURLConnection を使用する場合、リクエストは非同期形式で行われます。これは、リクエストの終了を待たずに続行することを意味します。

このデリゲートは、次のメソッドを実装する必要があります。

connection:didReceiveResponse : called after the connection is made successfully and before receiving any data. Can be called more than one time in case of redirection.
connection:didReceiveData : called for each bloc of data.
connectionDidFinishLoading : called only one time upon the completion of the request, if no error.
connection:didFailWithError : called on error.

例: -

NSData *data = [[NSMutableData alloc] init];

    NSURL *url_string = [NSURL URLWithString:
                     @"Your URL"];
    NSURLRequest *request = [NSURLRequest requestWithURL:url_string];
    NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:request
                                                                  delegate:self];
    if (!conn) {
        // this is better if you @throw an exception here
        NSLog(@"error while starting the connection");
        [data release];
    }

受信した生データのブロックごとに、このメソッドでここにデータを追加できます。

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)someData {
    [data appendData:someData];
}

connectionDidFinishLoading正常に受信されたデータの最後に呼び出されます

于 2013-09-24T10:03:02.983 に答える
0

このコードを使用して、さらにアクションをロードします

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    //scrollView.contentSize.height-scrollView.frame.size.height indicates UItableView scrool end
    if (scrollView.contentOffset.y >= scrollView.contentSize.height-scrollView.frame.size.height)
    {
        if(loadMore)
        {
            loadmore=no;
            //call your Web service
        }
    }
}
于 2013-09-24T10:25:38.863 に答える