【发布时间】:2016-08-13 22:40:05
【问题描述】:
希望您能帮助我...我这几天一直在尝试解决这个问题。
我使用 Parse (www.parse.com) 作为我的后端,并将其托管在我自己的 AWS 服务器上。
应用的结构: 在 AppDelegate 中,如果用户已登录,则显示一个 ViewController,它设置了我的 SlideMenuControllerSwift (https://github.com/dekatotoro/SlideMenuControllerSwift) 和我的 TabBarController。 [故事板][1]
在我的标签栏控制器中,我有一个导航控制器,当我点击一行时,它会连接到另一个 UITableViewController。
1) 我点击一行,它对我的解析数据库执行异步查询
2) 数据填充表格然后消失
3) 如果我更改选项卡并返回主选项卡,数据会重新出现
还有
1) 我点击一行,它对我的解析数据库执行异步查询
2) 数据填充表格然后消失
3)如果我回到原来的 UITableViewController,它并不能正常转换回来,我需要来回切换标签,直到它重新出现
代码:
我使用 storyboard 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")
}
}
【问题讨论】:
-
因为我不能把这个放在原来的帖子里。这是我的故事板的截图:imgur.com/Hntac8L
-
你是否在后台线程中的某个地方调用
tableView.reloadData()? -
不行,只有在指定Docs更新时才在主线程调用loadView,在viewWillAppear中调用reloadData()时
标签: ios iphone swift uitableview parse-platform