No pointer path to use table cell in Swift

I noticed that there are a lot of questions in Obj-C, but I hardly remember Obj-C, and each of the answers was specific to the question. Here I get this error: “There is no pointer path to use the table cell” sometimes when the application is updated. I notice that when I do not update, but leave and reopen the table view, the formatting is destroyed.

Here is my update method, which is used in several places:

@IBAction func loadData(){ timeLineData.removeAllObjects() //pulls the data from the server var findTimeLineData: PFQuery = PFQuery(className: "Sweets") findTimeLineData.findObjectsInBackgroundWithBlock{ (objects:[AnyObject]!, error: NSError!) -> Void in if !error{ for object:PFObject! in objects{ self.timeLineData.addObject(object) } let tempArray: NSArray = self.timeLineData.reverseObjectEnumerator().allObjects self.timeLineData = tempArray as NSMutableArray //reloads the data in the table view self.tableView.reloadData() } } } 

And the tableview method:

 override func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell? { let cell: SweetTableViewCell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as SweetTableViewCell let sweet: PFObject = self.timeLineData.objectAtIndex(indexPath.row) as PFObject //part of the animation cell.sweetTextView.alpha = 0 cell.userNameLabel.alpha = 0 cell.timestampLabel.alpha = 0 cell.sweetTextView.text = sweet.objectForKey("content") as String //add the date var dateFormatter: NSDateFormatter = NSDateFormatter() dateFormatter.dateFormat = "HH:mm yyyy-MM-dd" cell.timestampLabel.text = dateFormatter.stringFromDate(sweet.createdAt) //finds the sweeter associated with a pointer var findSweeter: PFQuery = PFUser.query() findSweeter.whereKey("objectId", equalTo: sweet.objectForKey("sweeter").objectId) findSweeter.findObjectsInBackgroundWithBlock{ (objects: [AnyObject]!, error: NSError!)-> Void in if !error{ let user: PFUser = (objects as NSArray).lastObject as PFUser cell.userNameLabel.text = user.username } } //adds animation UIView.animateWithDuration(1, animations: { cell.sweetTextView.alpha = 1 cell.userNameLabel.alpha = 1 cell.timestampLabel.alpha = 1 }) return cell } 

Any idea what causes the error?

+5
source share
1 answer

What causes the problem for you: when scrolling through the table, TableView deactivates the cell that it is trying to manipulate your asynchronous call to analyze the server.

You can overcome this problem: 1- in the Sweets table on Parse, save the PFUser object as a pointer 2- in your loadData function, select the user from the request using the includeKey method for PFQuery

If you change accordingly, you do not have to query PFUser every time cellForRowAtIndexPath is called.

0
source

Source: https://habr.com/ru/post/1201000/


All Articles