几秒钟后刷新Alamofire请求无法正常工作

时间:2018-02-27 14:35:25

标签: ios swift alamofire

  1. 我在viewdidload中使用了带选择器功能的计时器
  2. 例如

    `
    1. var timer = Timer.scheduledTimer(timeInterval: 0.4, target: self,selector: #selector(HomeViewController.getRequest), userInfo: nil, repeats: true) 用于json解析alamofire并使用集合视图填充数据

    2. 计时器和函数正常运行但json数据连续添加到数组中。在视图集合视图上持续显示数据。

    3. 我想在几秒钟之后刷新Alamofire请求但不是整个函数,因为json数据会推送到数组和字典中。

    4. 我的getRequest()代码:

      getRequest()

1 个答案:

答案 0 :(得分:1)

我想你需要在添加新数据之前清空数组,所以你可以在for循环之前添加下面的代码:

self.lawNameArray.removeAll()
self.lawImageArray.removeAll()
self.dataArray.removeAll()
self.lawIdArray.removeAll()
self.lawStatusArray.removeAll()