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)
}
}
können Sie enthalten den Code von Ihrer 'SecondHomeViewCell' Klasse – Danoram
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