2011-01-06 10 views

答えて

0

これは実行可能ではありません。表示時に をロードし、Webサービスを呼び出してオプションの配列を作成し、テーブルビュー用のテーブルデータソース関数を呼び出します。

1

Webサービスから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 
関連する問題