Iphone 在TableView中自动加载更多文章

Iphone 在TableView中自动加载更多文章,iphone,objective-c,xcode,uitableview,Iphone,Objective C,Xcode,Uitableview,我有TableView,在这个TableView中我正在打印文章。现在,用户必须单击导航栏中的项目进行更新(通过json从web下载更多文章)。我想,而且我认为,当用户滚动到底部时,会自动显示加载单元格,并开始从web加载或获取更多文章,这会更好 接下来是我的问题: 如何放置显示加载指示器的额外单元格 和加载文本如何自动获得更多的文章 此功能位于iphone应用程序“app Store”中,但单击“加载更多项目” 也许是更好地把按钮加载更多的文章 欢迎所有示例和建议 谢谢你的帮助我也很喜欢我的应

我有TableView,在这个TableView中我正在打印文章。现在,用户必须单击导航栏中的项目进行更新(通过json从web下载更多文章)。我想,而且我认为,当用户滚动到底部时,会自动显示加载单元格,并开始从web加载或获取更多文章,这会更好

接下来是我的问题:

  • 如何放置显示加载指示器的额外单元格
  • 和加载文本如何自动获得更多的文章
  • 此功能位于iphone应用程序“app Store”中,但单击“加载更多项目”

    也许是更好地把按钮加载更多的文章

    欢迎所有示例和建议


    谢谢你的帮助

    我也很喜欢我的应用程序中的这个东西, 在这里,您可以使用AsyncImage类,该类可用于在后台下载带有url的图像,从而使您的tableview滚动平滑

    这里有两个链接,希望这能帮助你在后台下载图片。。。 1.https://github.com/Koolistov/Image-Cache 2.https://github.com/rs/SDWebImage

    第二件事,你们想下载在底部的另一个数据和细胞,然后在这里,若你们使用1个条件,然后它的工作,你们喜欢

    cellforrowatinexpath
    tableview委托方法中

    if(indexPath.row==[yourArray count]-1){
    
       .....do somthing which you like.....(Reload table with your json or another data)
    
    }
    
    这里只有一个简单的逻辑,另一个更明智的想法是把按钮放在最后一行。。。 希望这对你有帮助。。
    :)

    我也喜欢我的应用程序中的这个东西, 在这里,您可以使用AsyncImage类,该类可用于在后台下载带有url的图像,从而使您的tableview滚动平滑

    这里有两个链接,希望这能帮助你在后台下载图片。。。 1.https://github.com/Koolistov/Image-Cache 2.https://github.com/rs/SDWebImage

    第二件事,你们想下载在底部的另一个数据和细胞,然后在这里,若你们使用1个条件,然后它的工作,你们喜欢

    cellforrowatinexpath
    tableview委托方法中

    if(indexPath.row==[yourArray count]-1){
    
       .....do somthing which you like.....(Reload table with your json or another data)
    
    }
    
    这里只有一个简单的逻辑,另一个更明智的想法是把按钮放在最后一行。。。 希望这对你有帮助。。
    :)

    这一个很简单,可以在末尾添加一个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
    
    //
    //TableViewController.m
    //可分割
    //
    //阿比泽·纳西尔于2011年7月7日创作。
    //
    #导入“TableViewController.h”
    #定义kNumberOfItems以添加8
    @TableViewController的实现
    @综合项目;
    //标记:-
    //马克:设置并拆除
    -(id)init{
    //新指定初始化器
    if(!(self=[super initWithStyle:UITableViewStyleGrouped])){
    返回零;//保释!
    }
    numberOfItemsToDisplay=kNumberOfItemsToAdd;//启动时显示10项
    回归自我;
    }
    -(id)initWithStyle:(UITableViewStyle)样式{
    //呼叫新指定的初始化器
    返回[自初始化];
    }
    -(无效)解除锁定{
    [项目发布];
    [super dealoc];
    }
    #pragma标记-视图生命周期
    -(布尔)应自动旋转指针面定向:(UIInterfaceOrientation)interfaceOrientation{
    //对于支持的方向返回YES
    返回(interfaceOrientation==UIInterfaceOrientationGraphic);
    }
    #pragma标记-表视图数据源
    -(NSInteger)表格视图中的节数:(UITableView*)表格视图{
    如果(numberOfItemsToDisplay==[项目计数]){
    返回1;
    }
    返回2;
    }
    -(NSInteger)表视图:(UITableView*)表视图行数节:(NSInteger)节{
    如果(节==0){
    返回numberOfItemsToDisplay;
    }否则{
    返回1;
    }
    }
    -(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath{
    静态NSString*CellIdentifier=@“ItemCell”;
    //如果indexPath小于numberOfItemsToDisplay,请配置并返回一个普通单元格,
    //否则,将其替换为按钮单元。
    UITableViewCell*单元格=[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    如果(!单元格){
    cell=[[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault重用标识符:CellIdentifier]自动释放];
    }
    如果(indexPath.section==0){
    cell.textlab.text=[items objectAtIndex:indexath.row];
    cell.textLabel.textAlignment=UITextAlignmentLeft;
    cell.textLabel.textColor=[UIColor blackColor];
    cell.textlab.font=[UIFont-boldSystemFontOfSize:17.f];
    }否则{
    cell.textLabel.text=[NSString stringWithFormat:NSLocalizedString(@“下一个%d项”,“要显示以加载更多内容的文本”),kNumberOfItemsToAdd];
    cell.textLabel.textAlignment=UITextAlignmentCenter;
    cell.textlab.textColor=[UIColor colorWithRed:0.196f绿色:0.3098f蓝色:0.52f alpha:1.f];
    cell.textlab.font=[UIFont boldSystemFontOfSize:14.f];
    }
    返回单元;
    }
    -(void)tableView:(UITableView*)tableView未选择RowatineXpath:(NSIndexPath*)indexPath{
    if(indexPath.section==1){
    NSUI整数,totalNumberOfItems=[items count];
    NSInteger newNumberOfItemsToDisplay=MIN(totalNumberOfItems,numberOfItemsToDisplay+kNumberOfItemsToAdd);
    NSMutableArray*indexPaths=[[NSMutableArray alloc]init];
    
    对于(i=numberOfItemsToDisplay;i这一项很简单,可以在末尾添加一个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
    
    //
    //TableViewController.m
    //可分割
    //
    //阿比泽·纳西尔于2011年7月7日创作。
    //
    #导入“TableViewController.h”
    #定义kNumberOfItems以添加8
    @TableViewController的实现
    @综合项目;
    //标记:-
    //马克:设置并拆除
    -(id)init{
    //新指定初始化器
    if(!(self=[super initWithStyle:UITableViewStyleGrouped])){
    返回零;//保释!
    }
    numberOfItemsToDisplay=kNumberOfItemsToAdd;//启动时显示10项
    回归自我;
    }
    -(id)initWithStyle:(UITableViewStyle)样式{
    //呼叫新指定的初始化器
    返回[自初始化];
    }
    -(无效)解除锁定{
    [项目发布];
    [super dealoc];
    }
    #pragma标记-视图生命周期
    -(BOOL)应该自动旋转指针吗
    
    - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
    {
        float offset = (scrollView.contentOffset.y - (scrollView.contentSize.height - scrollView.frame.size.height));
        if (offset >= 0 && offset <= 5) {
            [self loadMoreData];
        }
    }