-1

嗨,我有一个UITableView。它从 Web 服务加载 numberof 数据。我想按 10 加载这个 tableview 10。最初它加载前 10 个项目。当用户滚动到末尾时,UITableView它应该从服务器加载接下来的 10 条记录。所以在我的scrollviewDidEndDeclarating代表中我这样说

`

 if (scrollView.tag==24) {


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

但问题是当我停止滚动时它会卡住,直到加载表格视图。谁能给我一个解决方案

谢谢

4

2 回答 2

0

试试 NSURLCONNECTION 这将帮助你调用异步 web 服务

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 回答