ios - UITableView 不显示内容,除非滚动或触摸单元格

标签 ios iphone swift uitableview parse-platform

我有 2 个不同的 UITableViews 显示用户可以在应用程序上发布的帖子。我正在使用 Parse Framework 在云端获取该信息。

在完成我的第一个 TableView 后,它工作得很好,所以我回收了该代码并对其进行了修改,以便它可以与显示来自数据库中不同表的数据的不同 UITableView 一起工作。

第一个 UITableView 按预期工作,但第二个不是,即使代码几乎相同,唯一改变的是它从中获取数据的表。

这是我用来从云端获取数据并在应用程序上显示的代码:

@IBAction func loadData() {
    timelineData.removeAllObjects()

    var findTimelineData:PFQuery = PFQuery(className: "posts")
    findTimelineData.orderByAscending("createdAt")

    findTimelineData.findObjectsInBackgroundWithBlock{
        (objects: [AnyObject]?, error: NSError?) -> Void in

        if error == nil{
            for object in objects!{
                let post:PFObject = object as! PFObject
                self.timelineData.addObject(post)
            }

            let array:NSArray = self.timelineData.reverseObjectEnumerator().allObjects
            self.timelineData = NSMutableArray(array: array)

            self.tableView.reloadData()
        }
    }
}


override func viewDidLoad() {
    super.viewDidLoad()

    navigationController?.navigationBarHidden = false
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
}

override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
    //return # of sections
    return 1
}

override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    //# of elements in the timeLineData array
    return timelineData.count
}


 override func tableView(tableView: UITableView?, cellForRowAtIndexPath indexPath: NSIndexPath?) -> UITableViewCell {
    let cell:TableViewCell = tableView!.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath!) as! TableViewCell

    let post:PFObject = self.timelineData.objectAtIndex(indexPath!.row) as! PFObject

    cell.postTextView.alpha = 0
    cell.usernameLabel.alpha = 0
    cell.timestampLabel.alpha = 0

    cell.postTextView.text = post.objectForKey("content") as! String

    var dataFormatter:NSDateFormatter = NSDateFormatter()
    dataFormatter.dateFormat = "yyyy-MM-dd HH:mm"
    cell.timestampLabel.text = dataFormatter.stringFromDate(post.createdAt!)

    // to get username from the post
    var showUsername:PFQuery = PFUser.query()!
    //the objectID is the same as the user in the two different tables
    showUsername.whereKey("objectId", equalTo: post.objectForKey("user")!.objectId!!)

    showUsername.findObjectsInBackgroundWithBlock{
        (objects: [AnyObject]?, error: NSError?) -> Void in
        if error == nil{
            let user = (objects as! [PFUser]).last
            cell.usernameLabel.text = user!.username

            UIView.animateWithDuration(0.5, animations: {
                cell.postTextView.alpha = 1
                cell.usernameLabel.alpha = 1
                cell.timestampLabel.alpha = 1
            })
        }
    }

    return cell
}

有什么想法吗?我已经尝试过此处的其他帖子,但无法解决此问题。

Cells in UITable Cells in debugger

最佳答案

我想通了。问题出在我的 Storyboard中。我使用的 UITextView 太大,无法放入 tableView,所以我猜它覆盖了单元格的内容,而不是让它在应用程序中显示。

谢谢大家的回复!!

关于ios - UITableView 不显示内容,除非滚动或触摸单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32002339/

相关文章:

ios - 如何使用SwiftUI使用“PDF”选择器打开“PDF”?

ios - UIStoryboard实例化ViewControllerWithIdentifier : Can we call this in background thread?

iphone - 我可以在 xcode 4.5 上将我的 iOS 部署目标更改为 5.0 吗?

iphone - 如何正确使用 ManagedObjectID?

ios - 使用隐藏的 SCNNode 捕获 SCNView 的图像/屏幕截图 : drawViewHierarchyInRect afterScreenUpdates not working

iphone - Objective c 类别和继承

ios - Core Data 在 iPhone4 等旧设备上速度很慢

ios - Swift 4 根据条件和计数过滤数组

带有 AnyView 的 SwiftUI 对象数组

objective-c - 防止在 segue 中关闭 View Controller