2016-08-19 57 views
3

我正在构建一个练习应用程序。我在TableViewController中有一系列练习,每个单元显示不同的练习。单元格延伸到UIViewController。在UIViewController中,我现在希望用户能够跳到下一个练习,而不必返回到TableViewController。用Swift中的新数据刷新UIViewController

如何刷新包含下一个练习的新数据的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() 
} 

谢谢!

回答

0

你可以使用我们的代码,很容易就可以做分页。我们已经回答了您的问题。

加载更多索引的示例;

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

感谢