【问题标题】:In my Table View I have no cell only section so, how can I Reload tableview in ios objective c?在我的表格视图中,我没有只有单元格的部分,所以如何在 ios 目标 c 中重新加载表格视图?
【发布时间】:2018-10-11 06:10:41
【问题描述】:

我尝试了TableView中的reload方法

[self.tableview reloadData];

也试过了

for (int i = 0; i<self->allMessageKey.count; i++) {                    

    NSIndexSet *sec = [NSIndexSet indexSetWithIndex:i];
    [self->chatTableView beginUpdates];

    //NSIndexPath *section = [NSIndexPath indexPathForRow:NSNotFound inSection:i];

    [self->chatTableView insertSections:sec withRowAnimation:UITableViewRowAnimationBottom];

    if (i == self->allMessageKey.count-1)
    {
        [self->chatTableView endUpdates];

        NSIndexPath *ip = [NSIndexPath indexPathForRow:NSNotFound inSection:self->allMessageKey.count-1];

        [self->chatTableView scrollToRowAtIndexPath:ip atScrollPosition:UITableViewScrollPositionNone animated:NO];
    }

}

数据没有在 tableview 中重新加载。我该怎么做?

【问题讨论】:

  • 你能解释一下没有单元格的部分吗?
  • 哪里可以重新加载tableview?
  • 你应该添加更多关于你的代码的细节。我们只能看到您如何尝试重新加载,但看不到您如何设置 TableView 的变量和委托

标签: ios objective-c uitableview


【解决方案1】:

只有部分没有单元格?

我也遇到过类似的问题

一些请求没有完成,你重新加载它 你需要等待它完成,

【讨论】:

  • 如果这是答案,最好添加 make 了解到底是什么问题。
【解决方案2】:

[self.tableView reloadData] 肯定会触发重新加载表格视图。

我建议检查您的 self.tableView 属性是否确实指向 UITableView 实例(我假设它是一个 IBOutlet 将在 Interface Builder 中加入)。

您可以通过向委托中的numberOfSections 和/或numberOfRowsInSection 方法添加断点或打印语句来验证它是否正在重新加载。它可能正在重新加载,但由于您的模型有问题,它看起来不像。

【讨论】:

    【解决方案3】:

    这就是我重新加载表格视图的方式。我创建了一个方法 reloadTable

    -(void)reloadTable{
        [self.tableView beginUpdates];
        [self.tableView endUpdates];
    }
    

    并在我需要的地方使用此代码调用此方法-

    [self  reloadTable];
    

    为了更好地理解,我在单击按钮后重新加载我的表,我正在更改表视图的约束常量。这是一个让你正确理解的例子-

    -(IBAction)addChemical1:(id)sender{
    
        _ans6Constraint.constant=1500;
    
        [self  reloadTable];
    }
    

    希望对你有帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-05-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多