2016-08-13 4 views
2

당신이 나를 도울 수 있다고 생각했습니다 ... 저는 지금 며칠 동안이 문제를 파악하려고 노력해 왔습니다.비동기 쿼리 후 UITableViewController가 사라짐

필자는 백엔드로 Parse (www.parse.com)를 사용하고 있으며 자체 AWS 서버에서 호스팅하고 있습니다. 응용 프로그램의

구조 : 사용자가 로그인하면 은 AppDelegate에에서, 내 SlideMenuControllerSwift (https://github.com/dekatotoro/SlideMenuControllerSwift) 내 TabBarController를 설정하는의 ViewController을 보여줍니다. [Storyboard] [1]

내 탭 표시 줄 컨트롤러에서 행을 클릭 할 때 다른 UITableViewController segues UITableViewController 연결하는 탐색 컨트롤러가 있습니다.

문제 : http://imgur.com/izdCBgt

1) 나는 행을 클릭하고 내 구문 분석 데이터베이스

2) 데이터 테이블을 채 웁니다 후 사라에 비동기 쿼리를 수행

3) 탭을 변경하고 기본 탭으로 돌아 가면 데이터가 다시 나타납니다.

1 ~ 10) 난 행을 클릭하고 내 구문 분석 데이터베이스

2) 데이터 테이블을 채우고 다음

3) 나는 원래있는 UITableViewController로 돌아갈 경우, 사라에 비동기 쿼리를 수행 제대로 다시 전환하고, 나는 그것이 다시 나타날 때까지 앞뒤로 탭을 변경할 필요가 없습니다

코드 :

나는 스토리 보드 SEGUE를 사용하여 문서 테이블 뷰 컨트롤러에 SEGUE. 다음은 내 DocumentsTableViewController의 관련 코드입니다.

class DocumentTableViewController: UITableViewController, UIDocumentInteractionControllerDelegate, UIImagePickerControllerDelegate, UINavigationControllerDelegate, MMCropDelegate { 

required init?(coder aDecoder: NSCoder) { 
    super.init(coder: aDecoder) 
    print("initDocs") 
} 

var specificDocs=[Document](){ 
    didSet{ 
     dispatch_async(dispatch_get_main_queue(), { 
      //we might be called from the parse block which executes in seperate thread 
      self.loadView() 
     }) 
    } 
} 


override func viewDidLoad() { 
    tableView.dataSource = self 
    tableView.delegate = self 

    print("we loadeD") 
    super.viewDidLoad() 

    navigationItem.title = "Job Documents" 

    let cameraButton = UIBarButtonItem(image: UIImage(named: "Camera"), style: .Plain, target: self, action: #selector(self.didPressCamera(_:))) 
    navigationItem.rightBarButtonItem = cameraButton 

    self.queryForTable() 

} 

override func viewWillAppear(animated: Bool) { 
    super.viewWillAppear(animated) 
    self.tableView.reloadData() 
} 


// Define the query that will provide the data for the table view 
func queryForTable() { 
    // Run a spinner to show a task in progress 
    let progressHUD = MBProgressHUD.showHUDAddedTo(self.view, animated: true) 
    progressHUD.label.text = "Loading..." 

    //2 using those jobActions to find which documents are mine 
    let query = PFQuery(className: Document.parseClassName()) 
    query.whereKey(Document.jobActionCol(), containedIn: jobActions) 
    query.includeKey(Document.documentCategoryCol()) 
//  do { 
//   let test = try query.findObjects() 
//   self.specificDocs = test as! [Document] 
//   progressHUD.hideAnimated(true) 
//  } catch { 
//   print("error!") 
//  } 
// FIND WHY THIS DOESNT WORK....WHAT THE F 
     query.findObjectsInBackgroundWithBlock { 
      (objects: [PFObject]?, error: NSError?) -> Void in 
      if error == nil { 
       // The find succeeded. 
       self.specificDocs = objects as! [Document] 
       print("done") 
       progressHUD.hideAnimated(true) 

      } else { 
       // Log details of the failure 
       print("Error: \(error!) \(error!.userInfo)") 
      } 
     } 
    } 


    // MARK: - Table view data source 

    override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 
     return specificDocs.count 

    } 

    override func numberOfSectionsInTableView(tableView: UITableView) -> Int { 
     return 1 
    } 

    override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 

     var cell:UITableViewCell? = tableView.dequeueReusableCellWithIdentifier("cellIdentifier") 
     if ((cell) == nil){ 
      cell = UITableViewCell.init(style: .Default, reuseIdentifier: "cellIdentifier") 
     } 

     cell!.textLabel?.text = specificDocs[indexPath.row].documentCategory!.type! 
     print("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!") 
//  print(UIApplication.sharedApplication().keyWindow?.performSelector("recursiveDescription")) 
     return cell! 
    } 


    deinit { 
     print("docs deinit") 
    } 
} 
+0

() self.tableView.reloadData에 self.loadView()를 호출 수정 작동합니다. 여기 내 스토리 보드의 스크린 샷입니다 : http : //imgur.com/Hntac8L – Rioner

+0

백그라운드 스레드의 어딘가에서'tableView.reloadData()'를 호출합니까? – FelixSFD

+0

아니요, 지정된 스레드가 업데이트 될 때 주 스레드에서만 loadView를 호출하고 viewWillAppear에서 reloadData()를 호출 할 때 – Rioner

답변

0

아, 이제 코드의 의도가 나타납니다. 하지만, 그 일에 어떤 이유가 있습니까? loadView()를 직접 호출하는 것은 옳지 않습니다.

tableView.dataSource = self 
tableView.delegate = self 

보기에서 처음으로 이동합니다 .Appear 및 구문 분석에서 너무 빨리 완료된 것입니다.

정상적인 방법은 아래와 같이 될 것입니다 : self.tableView.reloadData에

var specificDocs=[Document](){ 
didSet{ 
    dispatch_async(dispatch_get_main_queue(), { 
     //we might be called from the parse block which executes in seperate thread 
     self.loadView() 
    }) 
} 

self.loadView()(). tableView.dataSource = self
요구하지 않는 tableView.delegate = self

.

도 필요하지 않습니다
override func viewWillAppear(animated: Bool) { 
super.viewWillAppear(animated) 
self.tableView.reloadData()} 

.

어쨌든, 당신의 코드는 그냥 원래의 게시물이 골로 연결되지 못했습니다 때문에

+0

Jay Choi! 그런 어리석은 짓이 내게 너무 많은 두통을 일으킨다는 것을 믿을 수 없다. 나는 내가 필요로했던 것보다 더 많은 것을 디버깅하고 있었다. – Rioner

관련 문제