UITableviewで使用されているURLの解析済み値を、各UITableviewsセルで使用されていたUICollectionview(水平方向にスクロール)に渡す方法はありますか?私はこれを迅速な言葉でしたい。uitableviewから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ビューに格納されたデータを転送する方法です。
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)
}
}
で、あなたの 'SecondHomeViewCell'クラスからのコードを含めることができます//
のUITableViewCellのカスタムクラスで関数を作成することによって、コレクションビューにデータを渡すことができます – Danoram
SecondHomeViewCellで、storyboard経由でコレクションビューを追加してください。@IBOutlet weak var collectionView:UICollectionView! 、cell.setData([indexPath.row]を収集)、そしてsetDataの内部で、この配列をコレクションビューのデータモデルとして設定します – jpulikkottil