Ios UITableViewController在异步查询后消失

Ios UITableViewController在异步查询后消失,ios,iphone,swift,uitableview,parse-platform,Ios,Iphone,Swift,Uitableview,Parse Platform,希望你能帮我…我已经试着解决这个问题好几天了 我使用Parse(www.Parse.com)作为我的后端,并将其托管在我自己的AWS服务器上 应用程序的结构: 在AppDelegate中,如果用户已登录,则显示一个设置我的SlideMenuControllerSwift()和我的TabBarController的ViewController。 [故事板][1] 在我的选项卡栏控制器中,我有一个导航控制器,当我单击一行时,它会引导到一个UITableViewController,该UITableV

希望你能帮我…我已经试着解决这个问题好几天了

我使用Parse(www.Parse.com)作为我的后端,并将其托管在我自己的AWS服务器上

应用程序的结构: 在AppDelegate中,如果用户已登录,则显示一个设置我的SlideMenuControllerSwift()和我的TabBarController的ViewController。 [故事板][1]

在我的选项卡栏控制器中,我有一个导航控制器,当我单击一行时,它会引导到一个UITableViewController,该UITableViewController会连接到另一个UITableViewController

问题

1) 我单击一行,它对我的解析数据库执行异步查询

2) 数据填充表,然后消失

3) 如果我更改选项卡并返回主选项卡,数据将重新出现

1) 我单击一行,它对我的解析数据库执行异步查询

2) 数据填充表,然后消失

3) 如果我返回到原始的UITableViewController,它将无法正确转换回,我需要来回更改选项卡,直到它重新出现

代码:

我使用序列图像板序列切换到documents表视图控制器。以下是my 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")
    }
}

哦,现在我明白你们代码的意图了。但是,你有什么理由这么做吗?直接调用loadView()是不对的

移动到视图中的第一个将出现,这将是一项工作,除非完成得太快,无法从解析接收

正常方式如下所示:

self.loadView()到self.tableView.reloadData()

tableView.dataSource=self

tableView.delegate=self

那不需要

那不需要太多


无论如何,您的代码都可以工作,只需将调用self.loadView()修改为self.tableView.reloadData()

,因为我无法将其放在原始帖子中。这是我的故事板的屏幕截图:你在后台线程的某个地方调用
tableView.reloadData()
吗?不,只有在指定的DDoS更新时,才在主线程上调用loadView,并且当view中的call reloadData()调用时,才会调用你Jay Choi!我真不敢相信这么愚蠢的事情会让我这么头疼。。。我调试的东西比我需要的多得多。
tableView.dataSource = self
tableView.delegate = self
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 viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
self.tableView.reloadData()}