Ios UITableView部分加载
嗨,我有一个Ios UITableView部分加载,ios,uitableview,scroll,Ios,Uitableview,Scroll,嗨,我有一个UITableView。它从web服务加载大量数据。我想加载这个tableview的是10乘10。最初它加载前10项。当用户滚动到UITableView的末尾时,它应该从服务器加载下10条记录。因此,在我的ScrollViewDiEndDeclarating委托中,我这样放置 ` 但问题是,当我停止滚动时,它会被卡住,直到加载表视图为止。有谁能给我一个解决办法吗 谢谢尝试NSURLCONNECTION,它将帮助您调用异步Web服务 NSURLConnection对象用于使用HTTP执
UITableView
。它从web服务加载大量数据。我想加载这个tableview的是10乘10。最初它加载前10项。当用户滚动到UITableView
的末尾时,它应该从服务器加载下10条记录。因此,在我的ScrollViewDiEndDeclarating
委托中,我这样放置
`
但问题是,当我停止滚动时,它会被卡住,直到加载表视图为止。有谁能给我一个解决办法吗
谢谢尝试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];
}
connectiondFinishLoading
将在成功接收数据后调用使用此代码加载更多操作
- (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
}
}
}
听起来您没有异步加载数据。因为您的Web服务不是异步的。。所以只要等到下10条记录出现,我能做些什么来停止这个呆滞的屏幕呢?在存储了来自webservice的数据之后,你需要调用重载函数。在reload函数中,需要从DB中获取数据,更新tableView的sourceArray并调用[self.tableView reloadData];
- (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
}
}
}