【问题标题】:Refresh UIViewController with new Data in Swift在 Swift 中使用新数据刷新 UIViewController
【发布时间】:2016-12-26 17:56:01
【问题描述】:

我正在构建一个锻炼应用程序。我的 TableViewController 中有一系列练习,每个单元格显示不同的练习。单元格连接到 UIViewController。在 UIViewController 中,我现在希望用户能够跳到下一个练习,而不必返回到 TableViewController。

如何刷新包含下一个练习的新数据的 ViewController? (类似于建表时的reloadData方法?)

我正在执行数组中的下一个练习,但我的页面没有刷新。 我的代码:

var exercise: Exercise?
var exerciseList: [Exercise]!

// toolbar item button pressed:
@IBAction func nextExercise(sender: UIBarButtonItem) {
  if let currentIndex = exerciseSet.indexOf(exercise!) {
    let nextIndex = currentIndex + 1
    let nextExercise = exerciseList[nextIndex]
    reloadData(nextExercise)
  }
}

private func reloadData(displayedExercise: Exercise){
    exercise = displayedExercise
    self.view.setNeedsDisplay()
}

谢谢!

【问题讨论】:

    标签: uiviewcontroller swift2 refresh


    【解决方案1】:

    您可以使用我们的代码并轻松进行分页。我们已经回答了您的问题。

    加载更多索引的示例;

    if indexPath.row == privateList.count - 1 { // last cell
        if totalItems > privateList.count { // more items to fetch
            loadItem() // increment `fromIndex` by 20 before server call
        }
    }
    

    Swift tableView Pagination

    谢谢

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-08-31
      • 1970-01-01
      • 1970-01-01
      • 2016-02-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-02-01
      相关资源
      最近更新 更多