2011-01-06 2 views
2

я использую UITableView, элементы списка из веб-службы ..Как добавить элементы в tableview на прокрутку iphone?

, что мне нужно сделать, это первый вызов 20 элементов из веб-службы и отображения в списке, когда пользователь прокрутки вниз называют еще 20 записей из WebService и добавить в таблицуview ..

как это сделать?

ответ

0

Невозможно сделать это на куски. при просмотре веб-службы времени вызова времени и введите массив параметров, а затем вызовите функцию источника данных таблицы для представления таблицы.

1

Вы можете загрузить 20 предметов из своего веб-сервиса и сохранить их в массиве. Затем создайте представление таблицы и отобразите эти 20 элементов. Если вы хотите, чтобы действие прокрутки инициировало загрузку, просто превратитесь в делегат UIScrollView в виде таблицы. В противном случае вы можете просто нажать кнопку «Загрузить еще». Когда вы хотите загрузить больше, просто загрузите данные и обновите количество элементов в списке и перезагрузите представление таблицы.

1
// 

#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 
Смежные вопросы