我做了一个tableview与JSON数据它包含分页和每个Webservices页面包含10个数据,但我希望当表视图滚动然后我想加载每一次只有5项是如何可能的?请给我解决方案。如何在表视图滚动时仅加载五个单元格?
我的代码,这个
-(void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
{
NSInteger currentOffset = scrollView.contentOffset.y;
NSInteger maximumOffset = scrollView.contentSize.height- scrollView.frame.size.height;
if (maximumOffset - currentOffset <= 0)
{
pageNum = pageNum + 1;
[self getData];
}
}
-(void)getData
{
NSURL * url=[NSURL URLWithString:[NSString stringWithFormat:@"http://www.truemanindiamagazine.com/webservice/news.php?page=%d",pageNum]];
dispatch_async(kBgQueue, ^{
data = [NSData dataWithContentsOfURL:url];
[self performSelectorOnMainThread:@selector(fetchedData:) withObject:data waitUntilDone:YES];
});
}
而且FetchData方法是
-(void)fetchedData:(NSData *)responsedata
{
UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
spinner.frame = CGRectMake(0, 0, 320, 44);
self.newsTable.tableFooterView = spinner;
if (responsedata.length > 0)
{
[spinner startAnimating];
NSError* error;
self.json = [NSJSONSerialization JSONObjectWithData:responsedata options:kNilOptions error:&error];
if ([[_json objectForKey:@"data"] isKindOfClass:[NSArray class]])
{
NSArray *arr = (NSArray *)[_json objectForKey:@"data"];
[self.imageArray addObjectsFromArray:arr];
[self.newsTable reloadData];
NSLog(@"images,%@",self.imageArray);
}
}
[self.spinner stopAnimating];
self.spinner.hidesWhenStopped=YES;
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return self.imageArray.count;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if (self.imageArray == nil || self.imageArray.count < 1)
{
return 0;
}
else
{
return 1;
}
[self.newsTable reloadData];
}
我知道这是问了很多次,但我没有得到Answer.Please帮助我。
这条线的工作self.mTenarray //删除前五个对象?而不明白mTenArry是什么? – 2014-10-30 09:05:47
你写的逻辑删除从该阵列中删除前五个对象。全局声明包含来自服务器的数据的tenarray – 2014-10-30 09:08:08
解决您的问题。 – 2014-10-30 09:24:29