2012-05-12 17 views
0

私はTableViewを持っています。このTableViewでは記事を印刷しています。ユーザーは、ナビゲーションバーの項目をクリックして更新する必要があります(json上のWebからより多くの記事をダウンロードしてください)。私はそれが良いと思うときは、ユーザーが下にスクロールすると、自動でロードセルを表示し、読み込みまたはWebからより多くの記事を取得することを示します。TableViewにもっと多くの記事を自動的に読み込む

私の質問は次のとおりです。

  1. はどのように余分なセルを入れているのローディングインジケータ
  2. とロードテキストはどのように自動的により多くの記事を取得するように見えるでしょうか?

この機能はiphoneアプリ「App Store」にありますが、click load more items。

ボタンを押した方が多くの記事を載せる方が良いでしょうか?

すべての例と提案は大歓迎です。

あなたがスムーズに自分のテーブルビューのスクロールして、バックグラウンドでURLでイメージをダウンロードすると便利ですAsyncImageクラスを使用することができますここに私はまた私のアプリでは、このことのように行う助け

答えて

2

この1つは、それがより多くの項目をロードするために最後にUITablecellを追加します簡単です。

// 
// TableViewController.m 
// PartialTable 
// 
// Created by Abizer Nasir on 07/07/2011. 
// 

#import "TableViewController.h" 

#define kNumberOfItemsToAdd 8 

@implementation TableViewController 

@synthesize items; 

// Mark: - 
// Mark: Set up and tear down 

- (id)init { 
    // New designated initialiser 
    if (!(self = [super initWithStyle:UITableViewStyleGrouped])) { 
     return nil; // Bail! 
    } 
    numberOfItemsToDisplay = kNumberOfItemsToAdd; // Show 10 items at startup 
    return self; 
} 


- (id)initWithStyle:(UITableViewStyle)style { 
    // Call out to the new designated initialiser 
    return [self init]; 
} 

- (void)dealloc { 
    [items release]; 
    [super dealloc]; 
} 

#pragma mark - View lifecycle 

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
    // Return YES for supported orientations 
    return (interfaceOrientation == UIInterfaceOrientationPortrait); 
} 

#pragma mark - Table view data source 

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { 
    if (numberOfItemsToDisplay == [items count]) { 
     return 1; 
    } 
    return 2; 
} 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
    if (section == 0) { 
     return numberOfItemsToDisplay; 
    } else { 
     return 1; 
    } 
} 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    static NSString *CellIdentifier = @"ItemCell"; 

    // If the indexPath is less than the numberOfItemsToDisplay, configure and return a normal cell, 
    // otherwise, replace it with a button cell. 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (!cell) { 
     cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 
    } 

    if (indexPath.section == 0) {    
     cell.textLabel.text = [items objectAtIndex:indexPath.row]; 
     cell.textLabel.textAlignment = UITextAlignmentLeft;   
     cell.textLabel.textColor = [UIColor blackColor]; 
     cell.textLabel.font = [UIFont boldSystemFontOfSize:17.f]; 

    } else { 
     cell.textLabel.text = [NSString stringWithFormat:NSLocalizedString(@"Next %d items", @"The text to display to load more content"), kNumberOfItemsToAdd]; 
     cell.textLabel.textAlignment = UITextAlignmentCenter; 
     cell.textLabel.textColor = [UIColor colorWithRed:0.196f green:0.3098f blue:0.52f alpha:1.f]; 
     cell.textLabel.font = [UIFont boldSystemFontOfSize:14.f]; 
    } 

    return cell; 
} 

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
    if (indexPath.section == 1) { 
     NSUInteger i, totalNumberOfItems = [items count];   
     NSUInteger newNumberOfItemsToDisplay = MIN(totalNumberOfItems, numberOfItemsToDisplay + kNumberOfItemsToAdd); 
     NSMutableArray *indexPaths = [[NSMutableArray alloc] init];   

     for (i=numberOfItemsToDisplay; i<newNumberOfItemsToDisplay; i++) { 
      [indexPaths addObject:[NSIndexPath indexPathForRow:i inSection:0]]; 
     }   

     numberOfItemsToDisplay = newNumberOfItemsToDisplay;     

     [tableView beginUpdates]; 
     [tableView insertRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationTop]; 
     [indexPaths release];     
     if (numberOfItemsToDisplay == totalNumberOfItems) { 
      [tableView deleteSections:[NSIndexSet indexSetWithIndex:1] withRowAnimation:UITableViewRowAnimationTop]; 
     }   
     [tableView endUpdates]; 
     // Scroll the cell to the top of the table 
     if (newNumberOfItemsToDisplay < totalNumberOfItems) { 
      dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 200000000), dispatch_get_main_queue(), ^(void){ 
       [tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionTop animated:YES]; 
      }); 
      [tableView deselectRowAtIndexPath:indexPath animated:YES]; 
     } else { 
      dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 200000000), dispatch_get_main_queue(), ^(void){ 
       [tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:totalNumberOfItems-1 inSection:0] atScrollPosition:UITableViewScrollPositionTop animated:YES]; 
      }); 
     } 

    }  
} 

@end 
0

に感謝の、 ...

こちら//github.com/Koolistov/Image-Cache 2.https://github.com/rs/SDWebImage

第二のものはバックグラウンドでダウンロードイメージのため、このヘルプあなた... 1.https 2人のリンク希望一番下にある別のデータとセルにダウンロードしたい場合は、ここで1 conditio nは、その後

if(indexPath.row==[yourArray count]-1){ 

    .....do somthing which you like.....(Reload table with your json or another data) 

} 

ここだけの単純なロジック、他の賢明な良いアイデアcellForRowAtIndexPathテーブルビューのデリゲートメソッドで

あなたが好きなその作品は... 希望...あなたの最後の行で、このヘルプあなたのボタンを配置しています。 。 :)

2

Q1:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
    return cellsCount <= 0 ? 0 : cellsCount + 1; 
} 

をし、負荷に多くのセルを作成します:負荷以上のステータスのための1個の以上の細胞を追加

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    if (indexPath.row == cellsCount) { 
     if (loadMoreCell == nil) { 
      self.loadMoreCell = [[LoadMoreTableCell alloc] initWithStyle:UITableViewCellStyleDefault 
                 reuseIdentifier:@"LoadMoreCellIdentifier"]; 
     } 
     return loadMoreCell; 
    } 
    ... 
} 

あなたがしたいカスタムLoadMoreTableCellことができますよう。

Q2:

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView 
{ 
    float offset = (scrollView.contentOffset.y - (scrollView.contentSize.height - scrollView.frame.size.height)); 
    if (offset >= 0 && offset <= 5) { 
     [self loadMoreData]; 
    } 
} 
関連する問題