2016-12-20 1 views
1

내 응용 프로그램에서 CloudKit에 문제가 있습니다. 처음에 뷰를로드하면 데이터가 완벽하게로드됩니다. 그러나 "새로 고침"을하면 "치명적인 오류가 발생합니다 : 색인이 범위를 벗어났습니다". 이상한 것은 코드에 차이가 없다는 것입니다 (적어도 나를 위해). 새로 고침 할 때 "수행"되지 않습니다 ("B"가 인쇄되지 않음). 디버거에 오류가 표시되지 않습니다.CloudKit perform

실마리가 있습니까?

미리 감사드립니다.

니코

의 viewDidLoad :

loadCloudData() 

handlePullToRefresh :

func handlePullToRefresh() { 
    loadCloudData() 
} 

loadCloudData :

func loadCloudData() { 
     DispatchQueue.main.async { 
      self.showMessage(titleText: NSLocalizedString("Loading ...", comment: "SwiftMessage Loading Title"), text: NSLocalizedString("Loading PixelCodes from Cloud", comment: "SwiftMessage Loading Title"), backgroundColor: UIColor.tileYellow(), textColor: UIColor.darkGray, image: #imageLiteral(resourceName: "cloud")) 
     } 

     dataCloud = [CKRecord]() 
     let query = CKQuery(recordType: PixelCodeType.recordType, predicate: NSPredicate(format: "TRUEPREDICATE", argumentArray: nil)) 
     query.sortDescriptors = [NSSortDescriptor(key: "title", ascending: true)] 

     print("A") 

     databasePublic.perform(query, inZoneWith: nil) { (results:[CKRecord]?, error:Error?) in 
      print("B") 
      if error != nil { 
       print("PixelCode from Cloud not Loaded!\n\(error!.localizedDescription)") 
       self.couldLoadCloadData = false 
       DispatchQueue.main.async { 
        SwiftMessages.hideAll() 

        if self.refreshControl != nil { 
         if self.refreshControl!.isRefreshing { 
          self.refreshControl!.endRefreshing() 
         } 
        } 

        //"Cloud" active 
        self.segmentedControl.setEnabled(true, forSegmentAt: 1) 
       } 
       self.handleError(title: NSLocalizedString("Error!", comment: "SwiftMessage error title"), text: error!.localizedDescription, errorTitle: "Cloud Loading Error:loadCloudData()", error: error) 
      } else { 
       if let data = results { 
        print("pixelCodes updated") 
        self.dataCloud = data 

        if results!.isEmpty { 
         self.couldLoadCloadData = true 
         self.isCloudDataLoaded = false 
        } else { 
         self.couldLoadCloadData = true 
         self.isCloudDataLoaded = true 
        } 

        self.uploadTimes() 

        DispatchQueue.main.async { 
         if self.refreshControl != nil { 
          if self.refreshControl!.isRefreshing { 
           self.refreshControl!.endRefreshing() 
          } 
         } 
         SwiftMessages.hideAll() 

         //"Cloud" active 
         self.segmentedControl.setEnabled(true, forSegmentAt: 1) 

         self.tableView.reloadData() 
        } 
       } 
      } 
     } 
    } 

답변

1

당신의 loadCloudData 함수는 빈 배열에 dataCloud 배열을 설정 않지만, 당신이 배열의 항목 수 및 항목의 수 때문에의 tableview에 reloadData를 호출하지 않는 것이 제일 먼저 그있는 tableview 생각합니다 배열에 있습니다 다릅니다.

배열을 지우거나 지우지 않으면 reloadData을 호출해야합니다.

+0

"dataCloud = [CKRecord]()"가 제거되었으며 모든 것이 잘 작동합니다! 왜 내가 그것을 제거하지 않을지 모르겠다. 고마워요 !!! –