2016-11-07 6 views
1

Wie kann ich analysierte Werte von einer URL, die in einer UITableview verwendet wurde, an eine UICollectionview übergeben (horizontal gescrollt), die in jeder der UITableviews-Zellen verwendet wurde? Ich möchte das in einer schnellen Sprache machen.Werte von uitableview an uicollectionview übergeben

Ich benutze ein Modell mit dem Namen "collectionCat".

Ich benutze auch Alamofire, um Daten von URL zu analysieren.

override func viewDidLoad() { 
    super.viewDidLoad() 

    self.startActivityAnimating(message: "", type: NVActivityIndicatorType.BallClipRotate, color: AppColor.AppRed, padding: 10) 
    Alamofire.request(.POST, "http://goringr.co.in/Mathrubhumi_project_ios/brand.php", parameters: ["": ""]) 
     .validate() 
     .responseJSON { response in 
      switch response.result { 
      case .Success: 
       print("Validation Successful") 
       self.jsonResultParse(response.result.value!) 
       self.stopActivityAnimating() 
      case .Failure(let error): 
       print(error) 
       self.stopActivityAnimating() 
       // return userCatagory 
      } 


    } 


    // Do any additional setup after loading the view. 
} 
    if JSONArray.count != 0 { 
     //_ = [UserCatagory]() 


     for i:Int in 0 ..< JSONArray.count { 

      let jObject = JSONArray[i] as! NSDictionary 

      let uCollect:CollectionCat = CollectionCat() 
      uCollect.brandid = (jObject["brandid"] as AnyObject? as? String) ?? "" 
      uCollect.brandname = (jObject["brandname"] as AnyObject? as? String) ?? "" 
      uCollect.result = (jObject["result"] as AnyObject? as? String) ?? "" 
      uCollect.noitems = (jObject["noitems"] as AnyObject? as? String) ?? "" 

      collect.append(uCollect) 
      print("collect COUNT ",collect.count) 
     } 

     self.newTable.reloadData() 

    } 



} 

Was ich weiß nicht, wie die gespeicherten Daten zu UICollection Ansicht zu übertragen, die in jeder Zelle des erwähnten UITableView ist.

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 
    // collectMaster = collect[indexPath.row] 

    let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! SecondHomeViewCell 

    // collectMaster = CollectionCat() 
    cell.get = ???? 

    return cell 
} 

Kann mir bitte jemand helfen?

Der Code der SecondHomeViewCell geht so.

import UIKit 
import Kingfisher 
import Alamofire 
import NVActivityIndicatorView 



class SecondHomeViewCell: UITableViewCell{ 

    @IBOutlet weak var collectionView: UICollectionView! 



    var genre:CollectionCat? = nil{ 
    didSet { 
       collectionView.reloadData() 

      } 

    } 




    func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { 
     //return genre!.brandid 

     // return genre 
     return 1 
    } 

    func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell { 
     let cell = collectionView.dequeueReusableCellWithReuseIdentifier("secondHome", forIndexPath: indexPath) as! SecondHomeCollectionViewCell 

      if let genre = genre { 
      cell.genre = genre.brandid[indexPath.row] 

     } 

     return cell 
    } 

    func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize { 
     let itemsPerRow:CGFloat = 4 
     let hardCodedPadding:CGFloat = 5 
     let itemWidth = (collectionView.bounds.width/itemsPerRow) - hardCodedPadding 
     let itemHeight = collectionView.bounds.height - (2 * hardCodedPadding) 
     return CGSize(width: itemWidth, height: itemHeight) 
    } 



} 
+0

können Sie enthalten den Code von Ihrer 'SecondHomeViewCell' Klasse – Danoram

+0

Fügen Sie in Ihrer SecondHomeViewCell die Sammlungsansicht über das Storyboard hinzu. @IBOutlet weak var collectionView: UICollectionView! , cell.setData (collect [indexPath.row), Und innerhalb von setData, setze dieses Array als Datenmodell der Sammlungsansicht – jpulikkottil

Antwort

0

ein Array in Ihrem Viewcontroller hinzufügen, nennen Sie es

var collCat = [CollectionCat]() 


func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 
    let collectMaster = collCat[indexPath.row] 

    let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! SecondHomeViewCell 


    cell.brandID = collectMaster.brandid 
    //and so on 

    return cell 
} 

Ist dies nicht die Antwort, die Sie suchen, bitte sagen Sie mir. Weil ich klarstellen wollte, aber ich habe noch nicht die Fähigkeit zu kommentieren. Ich muss 50 Reputation erreichen, um etwas kommentieren zu können.

+0

Gerade habe ich den Code für die secondHomeViewCell hinzugefügt. Können Sie sich das bitte auch anschauen und mir auch eine Antwort geben. –

+0

kannst du mir bitte auch sagen wie ich es in der SecondHomeViewCell nennen soll –

0

Sie können Daten in Sammlung Ansicht vorbei Funktion in UITableViewCell benutzerdefinierte Klasse erstellen

class SecondHomeViewCell: UITableViewCell{ 
//Array containing modals for particular tableview cell index path 


var arrDataFromViewController = NSArray() 
    func getData(arrData:NSArray){ 
     arrDataFromViewController = arrData 
     collectionView.delegate = self 
     collectionView.dataSource = self 
     collectionView.reloadData() 
     } 


    @IBOutlet weak var collectionView: UICollectionView! 



    var genre:CollectionCat? = nil{ 
    didSet { 
       collectionView.reloadData() 

      } 

    } 




    func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { 
     //return genre!.brandid 

     // return genre 
     return 1 
    } 

    func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell { 
     let cell = collectionView.dequeueReusableCellWithReuseIdentifier("secondHome", forIndexPath: indexPath) as! SecondHomeCollectionViewCell 

      if let genre = genre { 
      cell.genre = genre.brandid[indexPath.row] 

     } 

     return cell 
    } 

    func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize { 
     let itemsPerRow:CGFloat = 4 
     let hardCodedPadding:CGFloat = 5 
     let itemWidth = (collectionView.bounds.width/itemsPerRow) - hardCodedPadding 
     let itemHeight = collectionView.bounds.height - (2 * hardCodedPadding) 
     return CGSize(width: itemWidth, height: itemHeight) 
    } 



} 

// Jetzt in Tableview Datenquelle Methode

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 
    // collectMaster = collect[indexPath.row] 

    let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! SecondHomeViewCell 

    // collectMaster = CollectionCat() 
    cell.getData = yourArray[indexPath.row]//Get Array data 

    return cell 
} 
Verwandte Themen