当表格被加载以及滚动时,我需要在单元格中显示数据。我在第一次运行应用程序时将数据输入到表行中,但是当我滚动表时,表不会更新所有值。它仅显示服务的最后一次获取值。
我的服务请求格式为:
http://vapp.sites.net/......userId=967730&rowsPerPage=10&nextCursorMark=1
注意 - 当我呼叫服务时,NextCursorMark会在响应时增加,我会在滚动时传递给下一个服务调用。当nextCursorMark为nil时,我必须停止滚动表,因为没有更多新的响应数据。
回应:
{
MESSAGE: "Success",
STATUS_CODE: 200,
REQUEST: [ ],
RESPONSE: {
OrderList: [..<items>..],
nextCursorMark: "2",
totalOrderCount: 45
}
}
当第一次加载表时nextCursorMark
值为1
,并且在每次滚动时,值将根据totalOrderCount
增加。如何在每个滚动滚动并调用服务时管理表视图数据源?
我的代码如下:
1 - 加载表格时
#pragma mark - UITableViewDataSource Methods
- (NSInteger)numberOfSectionsInTableView:(UITableView *)theTableView
{
return self.arrOrderList.count;
}
- (NSInteger)tableView:(UITableView *)theTableView numberOfRowsInSection:(NSInteger)section
{
OrderList * objOrderList = (OrderList *)[self.arrOrderList objectAtIndex:section];
return objOrderList.orderDetailsList.count;
}
- (UITableViewCell *)tableView:(UITableView *)theTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier = @"OrderDetailsListCell";
OrderDetailsListCell * cell = (OrderDetailsListCell *)[theTableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil) {
cell = [[OrderDetailsListCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
}
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
OrderList * objOrderList = (OrderList *)[self.arrOrderList objectAtIndex:indexPath.section];
OrderDetailsList * objOrderDetailsList = (OrderDetailsList *)[objOrderList.orderDetailsList objectAtIndex:indexPath.row];
[cell loadDataWithOrderDetailList:objOrderDetailsList];
return cell;
}
- (void) ServiceCallForOrderHistoryWithCurrentPageMark:(NSString *)page
{
if(![[VCSpinnerView sharedInstance] isSpinnerAddedToTheView:self.view])
[[VCSpinnerView sharedInstance] showInView:self.view];
__block __weak VCMyOrderViewController* blockMyOrderListView = self;
[[VCModelManager sharedInstance] getMyOrderDetail:[[VCConfiguration sharedConfig] getLoggedInUserId] andPageNumber:page completionBlock:^(id result, NSError *error)
{
if (!error)
{
blockMyOrderListView.orderHistoryDataObject = (OrderHistoryBaseClass *)result;
dispatch_async(dispatch_get_main_queue(), ^{
[blockMyOrderListView setDataSourceMyOrders:blockMyOrderListView.orderHistoryDataObject.rESPONSE];});
}
else
{
NSLog(@"\nError->%@",[error debugDescription]);
}
dispatch_async(dispatch_get_main_queue(), ^{
[[VCSpinnerView sharedInstance] removeSpinnerView];
});
}];
}
- (void)setDataSourceMyOrders:(OrderRESPONSE *)response
{
self.orderHistoryDataObject.rESPONSE = response;
[self setPageMark:self.orderHistoryDataObject.rESPONSE.nextCursorMark];
[self setPageCount:[self.orderHistoryDataObject.rESPONSE.totalOrderCount integerValue]];
self.arrOrderList = [NSMutableArray arrayWithArray:self.orderHistoryDataObject.rESPONSE.orderList];
TrackOrderView *trackOrderView = [[TrackOrderView alloc] init];
[trackOrderView setDelegate:self];
[self.tblMyOrder setTableHeaderView:trackOrderView];
[self.tblMyOrder reloadData];
}
2 - 滚动表格时
- (void) scrollViewDidScroll:(UIScrollView *)scrollView
{
if (self.arrOrderList.count < self.pageCount)
{
[self ServiceCallForOrderHistoryWithCurrentPageMark:self.pageMark];
}
}
答案 0 :(得分:0)
你需要:
beginUpdates
,然后调用insertRowsAtIndexPaths:withRowAnimation:
,然后调用endUpdates