I
I
Ivan2015-12-23 20:50:01
Swift
Ivan, 2015-12-23 20:50:01

Doesn't open DetailView by tap on TableView?

In fact, it does not open the view with a detailed description of the product by tapping on the tableview, the
data is loaded from Parse.com
, here is a piece of the tableview code

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        
     
        let detailview = segue.destinationViewController as! DetailView
        
        if let indexPath = self.tableView.indexPathForSelectedRow {
            _ = Int(indexPath.row)
            print(indexPath.row)
            detailview.currentObject = (indexPath.row as! PFObject)
        }
    }

here is the detailview code
class DetailView: UIViewController {

    var currentObject : PFObject?

    
    @IBOutlet weak var name: UILabel!
    @IBOutlet weak var opysanie: UITextView!
    @IBOutlet weak var price: UILabel!
    @IBOutlet weak var image: UIImageView!
    
    
    override func viewDidLoad() {
        super.viewDidLoad()

        if let object = currentObject {

            name.text = object["name"] as? String
            opysanie.text = object["opisanie"] as? String
            price.text = object["price"] as? String
        }
  
    }

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
An, 2015-12-24
@ivanm38

Something strange is going on there. IndexPath contains the indices of the selected cell, such as cell 2 of section 3 is selected. And you force it to your internal object. In swift, the use of as! Well, it's damn undesirable. If it appears, then something is wrong and needs to be rewritten.
On the problem, you need to pull out the desired object, the one that you push into the cell in the tableView:cellForIndexPath method (I write from memory)
detailView.currentObject = data[indexPath.row]
But the problem can be any other. With the code that you have it should fall. If it does not open, then see if it enters the methods

C
castroy10, 2015-12-24
@castroy10

Data from parse.com is retrieved via PFQuery
let object = PFQuery(className: "your class name")
then you need to determine on which product the user tapped, and use this key value to pull data from parse.com via
object.whereKey
object. findObjectsInBackgroundWithBlock
Colleagues, correct me if I'm wrong.

I
Ivan, 2015-12-25
@ivanm38

Lord developers!
In general, now the application does not
crash, but it does not display the code on the detailview either.
Here's the code, tell me what's wrong?

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        if(segue.identifier == "DetailSegue"){
            // check for / catch all visible cell(s)
            if let indexPath = self.tableView.indexPathForSelectedRow {
                let object: String = testarray[indexPath.row]
                (segue.destinationViewController as! DetailView).currentObject = object as? PFObject
                
            }        }
    }

and
var currentObject : PFObject?

    
    @IBOutlet weak var name: UILabel!
    @IBOutlet weak var opysanie: UITextView!
    @IBOutlet weak var price: UILabel!
    @IBOutlet weak var image: UIImageView!
    
    
    override func viewDidLoad() {
        super.viewDidLoad()

        if let object = currentObject {

            name.text = (object["name"] as! String)
            opysanie.text = object["opisanie"] as! String
            price.text = (object["price"] as! String)
        }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question