당신이 나를 도울 수 있다고 생각했습니다 ... 저는 지금 며칠 동안이 문제를 파악하려고 노력해 왔습니다.비동기 쿼리 후 UITableViewController가 사라짐
필자는 백엔드로 Parse (www.parse.com)를 사용하고 있으며 자체 AWS 서버에서 호스팅하고 있습니다. 응용 프로그램의
구조 : 사용자가 로그인하면 은 AppDelegate에에서, 내 SlideMenuControllerSwift (https://github.com/dekatotoro/SlideMenuControllerSwift) 내 TabBarController를 설정하는의 ViewController을 보여줍니다. [Storyboard] [1]
내 탭 표시 줄 컨트롤러에서 행을 클릭 할 때 다른 UITableViewController segues UITableViewController 연결하는 탐색 컨트롤러가 있습니다.
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")
}
}
() self.tableView.reloadData에 self.loadView()를 호출 수정 작동합니다. 여기 내 스토리 보드의 스크린 샷입니다 : http : //imgur.com/Hntac8L – Rioner
백그라운드 스레드의 어딘가에서'tableView.reloadData()'를 호출합니까? – FelixSFD
아니요, 지정된 스레드가 업데이트 될 때 주 스레드에서만 loadView를 호출하고 viewWillAppear에서 reloadData()를 호출 할 때 – Rioner