【问题标题】:How to autoscroll Custom Table View cell in Objective C如何在Objective C中自动滚动自定义表格视图单元格
【发布时间】:2017-01-10 05:23:53
【问题描述】:

我是 iOS 新手,我遇到了关于自动滚动表格视图单元格的问题。 我正在使用这样的代码

- (void)viewDidAppear:(BOOL)animated{

  [table setContentOffset:CGPointMake(0.0, table.contentSize.height - table.bounds.size.height)
                 animated:YES]; 

  [tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:[headarray count]-1 inSection:0]                                                
                   atScrollPosition:UITableViewScrollPositionBottom
                           animated:YES];
}

但它向我展示了我在这段代码中做错了什么。在此先感谢!

我在 connectionDidFinishLoading 方法中尝试了这样的代码

if ([headarray count] != 0) {

            NSIndexPath *indexPath = [NSIndexPath indexPathForRow:[headarray count]-1 inSection:0];
            [Newstable scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionBottom animated:NO];
        } 

【问题讨论】:

  • 您的代码绝对正确,但请检查此 [musicGenre count]-1 inSection:0] ,它返回的内容,检查其值和类。
  • @muja 试试我的代码,然后删除你的 [table setContentOffset:CGPointMake(0.0, table.contentSize.height - table.bounds.size.height) animated:YES];这一行
  • @Muju 你想像聊天一样滚动到表格的最后一行吗?
  • 你的数据源数组是哪个? headarray 或 musicGenre ?
  • @PiyushPatel Head 数组是我的数据源数组。

标签: ios objective-c uitableview uiscrollview


【解决方案1】:

查看此链接https://github.com/danielamitay/DAAutoScroll。您可以使用这些类来自动滚动您的表格视图。 1. 导入类

导入“DAAutoScroll.h”

- (void)viewDidLoad {
    [self performSelector:@selector(scrollDown) withObject:self afterDelay:3.0];
}

-(void)scrollDown{

    yourtableview.scrollPointsPerSecond = 20.0f;
    [yourtableview startScrolling];

}
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
{
    if (!decelerate) {
        [yourtableview startScrolling];
    }
}

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
    [yourtableview startScrolling];
}

【讨论】:

  • 在演示中它工作得很好,但是当我在项目中使用它时它不起作用。
  • @Muju 当您尝试在项目中使用它时有什么问题?
  • @Muju Thant 表示您不知道如何在您的项目中实现它,因为演示不可能完美运行,但在您的项目中却无法运行。
  • @PiyushPatel 我使用了自定义表格视图单元格,并在我的项目中实现了它。是的,可能是我在实施时做错了什么。
  • @Muju : 不管你是否使用自定义单元格。
【解决方案2】:
[tableviewname setContentOffset:CGPointMake(0, ([arrayofcontact count]-10)*cellheight) animated:YES];

【讨论】:

  • 这段代码有什么作用,为什么能解决问题?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多