【问题标题】:Scrolling to a certain custom cell when loading the table加载表格时滚动到某个自定义单元格
【发布时间】:2014-02-14 09:39:43
【问题描述】:

我正在构建一个 celander 应用程序,我希望日历在启动时滚动到当前月份。我每个月都使用自定义单元格。我发现从这个网站上实现这一点的代码是这样的:

    [self.bahraincld reloadData];

    NSIndexPath *scrollto = [NSIndexPath indexPathForRow:2 inSection:1];

    [self.bahraincld scrollToRowAtIndexPath:scrollto
                           atScrollPosition:UITableViewScrollPositionTop animated:YES];

我在视图中使用它确实加载了。它给了我一个信号 SIGABRT。

  • 此代码正确吗?如果我希望它在用户启动日历时工作,我应该在哪里使用它。

谢谢。

【问题讨论】:

    标签: iphone cocoa-touch uitableview


    【解决方案1】:

    您最好将此代码放入viewDidAppear,因为您的tableView 尚未加载数据,因此未创建单元格。在您的情况下SIGABRT,是因为第 2 行超出了界限。

    【讨论】:

    • 是的,它确实看到了我对我具体所做的事情的回答。谢谢
    【解决方案2】:

    这是我所做的,希望对某人有所帮助。

    //in the view will appear reload your table.
    -(void)viewWillAppear:(BOOL)animated
     {
    [self.yourtable reloadData];
     }
    
    //in the view did appear, value = defining which costume cell to move to.
    -(void)viewDidAppear:(BOOL)animated 
    {
    [super viewDidAppear:animated];
    int value = 5;
    NSIndexPath *scrollto = [NSIndexPath indexPathForRow:value inSection:0];
    [self.yourtable scrollToRowAtIndexPath:scrollto
                           atScrollPosition:UITableViewScrollPositionTop animated:YES];
     }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-10-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多