【问题标题】:Choppy animation while pushing UITableViewController with static cells使用静态单元格推送 UITableViewController 时出现断断续续的动画
【发布时间】:2019-07-10 07:47:13
【问题描述】:

我有一个带有静态单元格的 UITableViewController。当我执行 push segue 时,动画有些不稳定。我已经弄清楚哪一行代码给出了问题。在 UITableViewController 的 viewWillAppear(_:) 方法中,我设置 self.tableview.isHidden = true。如果我删除这行代码,那么它工作正常。但是,我在进行网络调用时需要这条线,并且我只想在收到响应后才显示 tableview。对此问题的任何解决方案将不胜感激。

【问题讨论】:

    标签: ios swift iphone uitableview uinavigationcontroller


    【解决方案1】:

    您应该从 Storyboard 中设置 TableView 的 Hidden 属性。您可以在属性检查器的“视图 > 绘图”下找到此复选框。你可以找到这个here的截图。

    话虽如此,您应该找到一种更好的方法来指示正在执行 API 调用。我会使用您的视图控制器可以遵循的协议。

    protocol ActivityIndicating {
        func showLoading()
        func hideLoading()
    }
    

    在你的 ViewController 类中,你会有这样的东西

    class ViewController: UIViewController, ActivityIndicating {
        //protocol methods
        func showLoading() {
            //implement logic to hide tableview, show indicator, etc.
        }
    
        func hideLoading() {
            //implement logic to show tableview, hide indicator, etc.
        }
    
        func someFunctionThatMakesAPIcalls() {
            showLoading()
            //makeAPICall and call hideLoading() once the api succeeds or fails
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-27
      • 1970-01-01
      • 2016-12-24
      • 2018-09-24
      • 1970-01-01
      相关资源
      最近更新 更多