我正在尝试从我的MainTableViewController(使用PFQueryTableViewController)到我的CommentsViewController的prepareForSegue
方法,但是,当我运行我的应用程序时,它不会显示数据。我希望能够在CommentsViewController的顶部看到数据,并且在同一个viewController中也与reply函数有关系。基本上,我希望将博客文章引入下一页,以便用户对该特定帖子发表评论。
这是我的MainTableViewController(注意:这不是我的整个文件,只是其中的一部分):
class MainTableViewController: PFQueryTableViewController
var blog:NSMutableArray! = NSMutableArray()
override func tableView(tableView: UITableView?, cellForRowAtIndexPath indexPath: NSIndexPath?, object: PFObject!) -> PFTableViewCell? {
let cell = tableView!.dequeueReusableCellWithIdentifier("BLCell", forIndexPath: indexPath!) as! Blog
if let userBlog : PFObject = self.blog.objectAtIndex(indexPath!.row) as! PFObject {
cell.writer.text = object["author"] as? String
cell.post.text = object["blog"] as? String
let dateUpdated = object.createdAt! as NSDate
let dateFormat = NSDateFormatter()
dateFormat.dateFormat = "h:mm a"
cell.dateTime.text = NSString(format: "%@", dateFormat.stringFromDate(dateUpdated)) as String
}
return cell
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if(segue.identifier == "blogDetail"){
let indexPath = self.tableView.indexPathForSelectedRow
let obj = self.objects[indexPath!.row] as! PFObject
let navVC = segue.destinationViewController as! UINavigationController
let commentVC = navVC.topViewController as! CommentsViewController
commentVC.blog = obj
}
}
这是我的CommentsViewController:
class DetailViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
var blog: PFObject?
var comments: String?()
func replyButtonPressed(sender: AnyObject!) {
blog?.addObject(commentField?.text, forKey: "comments")
blog?.saveInBackground()
if let tmpText = commentField?.text {
comments?.append(tmpText)
}
commentField?.text = ""
print(comments?.count)
self.commentField?.resignFirstResponder()
self.tableView.reloadData()
}