UITableView를 사용하여 웹 서비스의 요소를 나열합니다.스크롤하는 아이폰에서 tableview에 요소를 추가하는 방법은 무엇입니까?
사용자가 웹 서비스에서 20 개 요소를 먼저 호출하고 목록에서 표시 할 때 사용자가 webservice에서 다른 20 개의 레코드를 호출하고 tableview에 추가하십시오 ..
어떻게 만드시겠습니까?
UITableView를 사용하여 웹 서비스의 요소를 나열합니다.스크롤하는 아이폰에서 tableview에 요소를 추가하는 방법은 무엇입니까?
사용자가 웹 서비스에서 20 개 요소를 먼저 호출하고 목록에서 표시 할 때 사용자가 webservice에서 다른 20 개의 레코드를 호출하고 tableview에 추가하십시오 ..
어떻게 만드시겠습니까?
이것은 가능하지 않습니다. 보기에서 로드 시간 웹 서비스를 호출하고 옵션의 배열을 만든 다음 테이블보기를 위해 테이블 데이터 소스 함수를 호출합니다.
웹 서비스에서 20 개의 항목을로드하여 배열에 저장할 수 있습니다. 그런 다음 표보기를 만들고 그 20 개의 항목을 표시하십시오. 스크롤 작업에서로드를 트리거하려면 테이블보기의 UIScrollView 대리자가됩니다. 그렇지 않으면 "추가로드"라는 버튼 만있을 수 있습니다. 더 많이로드하려면 데이터를 다운로드하고 목록의 항목 수를 업데이트 한 다음 테이블보기를 다시로드하십시오.
//
#import "ViewController.h"
@interface ViewController()
@end
@implementation ViewController
static int m=5;
static int resultsSize = 5; ;
- (void)viewDidLoad {
[super viewDidLoad];
recipes=[NSArray arrayWithObjects:@"one",@"two",@"three",@"four",@"five",@"six",@"seven",@"eight",@"nine",@"ten",@"eleven",@"twelve", nil];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return m;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *simpleTableIdentifier = @"SimpleTableItem";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
}
cell.textLabel.text = [recipes objectAtIndex:indexPath.row];
return cell;
}
- (void)scrollViewDidEndDragging:(UIScrollView *)aScrollView
willDecelerate:(BOOL)decelerate
{
CGPoint offset = aScrollView.contentOffset;
CGRect bounds = aScrollView.bounds;
CGSize size = aScrollView.contentSize;
UIEdgeInsets inset = aScrollView.contentInset;
float y = offset.y + bounds.size.height - inset.bottom;
float h = size.height;
float reload_distance = 50;
if(y > h + reload_distance) {
NSInteger i;
NSMutableArray *arrayWithIndexPaths = [NSMutableArray array];
for (i = resultsSize; i < resultsSize + 2; i++)
{
[arrayWithIndexPaths addObject:[NSIndexPath indexPathForRow:i inSection:0]];
}
m=resultsSize+2;
resultsSize =resultsSize+2;
[table insertRowsAtIndexPaths:arrayWithIndexPaths withRowAnimation:UITableViewRowAnimationFade];
}
}
//}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 50;
}
@end