gpt4 book ai didi

ios - 将值从 uitableview 传递到 uicollectionview

转载 作者:行者123 更新时间:2023-11-28 08:24:30 25 4
gpt4 key购买 nike

如何将已在 UITableview 中使用的 url 中的已解析值传递到已在每个 UITableviews 单元格中使用的 UICollectionview(水平滚动)?我想用快速的语言来做这件事。

我正在使用名为“collectionCat”的模型。

import Foundation

public class CollectionCat{



var brandid:String = ""
var brandname:String = ""
var result:String = ""
var noitems:String = ""



}

我也在使用 Alamofire 来解析来自 url 的数据。

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()

}



}

我不知道如何将存储的数据传输到上述 UITableview 的每个单元格中的 UICollection View 。

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
}

谁能帮我解决这个问题?

SecondHomeViewCell 的代码是这样的。

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)
}



}

最佳答案

在你的ViewController中添加一个数组,调用它

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
}

如果这不是您要找的答案,请告诉我。因为我想澄清,但我还没有发表评论的能力。我需要达到 50 声望才能发表评论并要求澄清。

关于ios - 将值从 uitableview 传递到 uicollectionview,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40460033/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com