0

Having issue when loading parse data into tableView cell. I think the issue is because of the tableView cell.

I use ObjectC for writing iOS app in the past few years.

I've checked that all the connections and identifier in storyboard had been connected and written correctly.


import UIKit

class TrendingTableViewCell: UITableViewCell {
    
    @IBOutlet weak var Label1: UILabel!
    @IBOutlet weak var ImageView1: UIImageView!
}


class Trending: UIViewController {
    
    @IBOutlet weak var TableView: UITableView!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        
        getdatafromparse()
    }
    
    var Saveddata: [UIImage] = []
    var Savetext1: [String] = []
    
    func getdatafromparse(){
        let query = PFQuery(className: "Content")
        //query.whereKey("userId", equalTo: (PFUser.current()?.objectId!)!)
        
        query.findObjectsInBackground(block: { (objects, error) in
            
            if let posts = objects{
                for object in posts {
                    if let post = object as? PFObject {
                        
                        self.Savetext1.append(post["heading"] as! String)
                        
                        //self.taskId.append(object.objectId!)
                        
                        
                        
                        
                    }
                    
                }
             self.TableView.reloadData()
            }
            
        })
    }
    
    func numberOfSections(in tableView: UITableView) -> Int {
        return 1
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier:"PostCell")as! TrendingTableViewCell
        
        cell.Label1!.text = Savetext1[indexPath.row]
        //cell.ImageView1?.image = Saveddata[indexPath.row]
        return cell
        
    }
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return self.Savetext1.count
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    
}

Error Log:

*** Assertion failure in -[UITableView _configureCellForDisplay:forIndexPath:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit/UIKit-3600.8.1/UITableView.m:8174

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UITableView (<UITableView: 0x101039000; frame = (0 121; 375 546); clipsToBounds = YES; autoresize = RM+BM; gestureRecognizers = <NSArray: 0x17024d770>; layer = <CALayer: 0x170033560>; contentOffset: {0, 0}; contentSize: {375, 8700}>) failed to obtain a cell from its dataSource ()'

2 Answers 2

1

Try This UITableViewDelegate and UITableViewDataSource

class Trending: UIViewController, UITableViewDelegate, UITableViewDataSource {


}
Sign up to request clarification or add additional context in comments.

1 Comment

wow. this is a quick respond. It solved my problem. Thank You! One more thing, may I know are there any other improvement(s) that I can made in the above code?
0

You have forgotten import Parse lib to file.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.