JB29.4
JB29.4

Reputation: 326

JSON data is returning empty cell in detailViewController?

I've a collectionViewCell(dynamic) with images and labels (loading from JSON) inside a tableview. what i want is if i click on any Cell (contains image/folders) it should display detailedViewController with its content(also from JSON). my mainViewController works fine. displays the DATA.

inside mainViewController i used didSelectItemAtIndexPath like this

func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
   println("USER TAPPED item# \(indexPath.item)")
   let subFolderView:SubFolderViewController = self.storyboard?.instantiateViewControllerWithIdentifier("subFolder") as! SubFolderViewController
   self.navigationController?.pushViewController(subFolderView, animated: true)
   subFolderView.imageSelected = self.Data[indexPath.row].AbsolutePath
   subFolderView.imageSelected = self.Data[indexPath.row].Name
   subFolderView.imageSelected = self.Data[indexPath.row].Description

BUT it is returning empty view when clicked.

in my secondViewController i have

var imageSelected:String!

func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
    var cell:SubFolderCollectionViewCell? = collectionView.dequeueReusableCellWithReuseIdentifier("CollectionViewCell", forIndexPath: indexPath) as? SubFolderCollectionViewCell
    cell?.subFolderDescription.text = self.Data[indexPath.row].Description
    cell?.subFolderName.text = self.Data[indexPath.row].Name

    let picUrl = self.Data[indexPath.row].AbsolutePath
    let url = NSURL(string: picUrl)
    if(url != nil) {  
        let data = NSData(contentsOfURL : url!)
        if(data != nil) {
            cell?.subImage?.image = UIImage(data: data!)
        }
    }
    return cell!
}

Please any one guide me to proceed further......i am new to iOS development and prefer swift!!!!!!!

IN my storyBoadrd both viewControllers contains

View,

Tableview,

TableViewCell,

ContentView,

collectionView,

collectionViewCell.

inside that imageView and labels to display the data

Any help is appreciated, Please let me know if u need more code............

Upvotes: 1

Views: 72

Answers (1)

iHardikTrivedi
iHardikTrivedi

Reputation: 559

Check your code..

you use didDeselectItemAtIndexPath instead of didSelectItemAtIndexPath method..

It's different tableview delegate method. change this and let me know if there is any issue.

Upvotes: 1

Related Questions