Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

同一个界面有两个collectionView的时候回出错 #89

Open
FzyJanm opened this issue Sep 25, 2019 · 2 comments
Open

同一个界面有两个collectionView的时候回出错 #89

FzyJanm opened this issue Sep 25, 2019 · 2 comments

Comments

@FzyJanm
Copy link

FzyJanm commented Sep 25, 2019

在collectionView中添加这个控件的时候回出现 代理错乱的情况 希望作者及时发现调整

@isdotjim
Copy link

搭个车...
想邀请Repo作者来w3c.group创建项目的对应小组。w3c.group是类似知识星球的社群工具,小组可设置为付费且有赞助功能,同时也是一个区块链主导的创作者社区。这是相关介绍:
http://t.cn/Ai1vLcCU
http://t.cn/Ai1vLcCG
http://t.cn/Ai1vLcCA

@12207480
Copy link
Owner

有代码 或者 截图吗

@JianWenXie
Copy link

我也是遇到了同样的情况
//
// HomeViewCtrl.swift
// VKIntlProperty
//
// Created by fox on 2021/2/3.
// Copyright © 2019 com.vk.TestP. All rights reserved.
//

import UIKit

class VKHomeViewCtrl: VKBaseViewCtrl {

var collectionView:UICollectionView!
var dataArr:Array<String>!
override func viewDidLoad() {
    super.viewDidLoad()
    dataArr = ["会所预定","物业公告","我的订单","工单报事","分类标题","分类标题"]
    setupUI()

}

func setupUI() {
    /// 左地址选择
    let leftView = UIView.init()
    let btn = UIButton.init(type: .custom)
    btn.titleOfNormal = "金色家园1栋"
    btn.imageOfNormal = UIImage.init(named: "nav_icon_ place")
    btn.titleColorOfNormal = UIColorFromHex(hexValue: Color_CommNavTitleBlack)
    btn.frame = CGRect.init(x: 0, y: 0, width: 140, height: 40)
    btn.layoutButton(with: .left, imageTitleSpace: 8)
    leftView.addSubview(btn)
    leftView.frame = CGRect.init(x: 0, y: 0, width: 140, height: 40)
    navigationItem.leftBarButtonItem = UIBarButtonItem.init(customView: leftView)
    
    let rightBtn = UIButton()
    rightBtn.layoutButton(with: .right, imageTitleSpace: 10)
    rightBtn.imageOfNormal = UIImage.init(named: "nav_btn_news_default")
    rightBtn.frame = CGRect.init(x: 0, y: 0, width: 40, height: 40)
    rightBtn.addTarget(self, action: #selector(pushMessageListCtr), for: .touchUpInside)
    navigationItem.rightBarButtonItem = UIBarButtonItem.init(customView: rightBtn)
    
    
   let layout = UICollectionViewFlowLayout.init()
    layout.scrollDirection = .vertical
    layout.minimumLineSpacing = 0
    layout.minimumInteritemSpacing = 0
    /// 如果设置家最小间距 直接给宽度会问题
    layout.itemSize = CGSize.init(width:(ScreenWidth - 0 )/3, height: (ScreenWidth-0)/3)
    collectionView = UICollectionView.init(frame: CGRect.zero, collectionViewLayout: layout)
    collectionView.dataSource = self
    collectionView.delegate = self
    collectionView.backgroundColor = UIColor.white
    collectionView.register(VKHomeCollectionCell.classForCoder(), forCellWithReuseIdentifier: "cellID")
  
    collectionView.register(UICollectionReusableView.classForCoder(), forSupplementaryViewOfKind:
        UICollectionView.elementKindSectionHeader, withReuseIdentifier: "headerView")
    view.addSubview(collectionView)
}

override func viewDidLayoutSubviews() {
    super.viewDidLayoutSubviews()
    collectionView.frame = view.bounds
}

@objc func pushMessageListCtr() {
    let vc = VKMessageListCtrl.init()
    navigationController?.pushViewController(vc, animated: true)
}

}

//MARK: - UICollectionViewDataSource,UICollectionViewDelegate
extension VKHomeViewCtrl: UICollectionViewDataSource,UICollectionViewDelegateFlowLayout,UICollectionViewDelegate{
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return dataArr.count
}

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {

    let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cellID", for: indexPath)as! VKHomeCollectionCell
    
    cell.titleLabel.text = dataArr[indexPath.row]
    return cell
}


func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {
    let view = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: "headerView", for: indexPath)
    
   let pageView = TYCyclePagerView()
    pageView.isInfiniteLoop = true
    pageView.dataSource = self
    pageView.delegate = self
    pageView.register(VKHomeCarouselCell.classForCoder(), forCellWithReuseIdentifier: "VKHomeCarouselCell")
    pageView.frame = CGRect.init(x: 16, y: 0, width: ScreenWidth - 32, height: 172)
    view.addSubview(pageView)
    //这里放轮播图
    return view
}

func collectionView(_ collectionView: UICollectionView,
                    layout collectionViewLayout: UICollectionViewLayout,
                    referenceSizeForHeaderInSection section: Int) -> CGSize {
    
    return CGSize(width: collectionView.bounds.width, height: 171
    )
}

func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {

    var vc:UIViewController!
    switch indexPath.row {
    case 0:
        vc = VKClubListCtrl.init()
        break
    case 1:
        vc = VKNotificationListCtrl.init()
        break
    case 2:
        vc = VKOrderListCtrl.init()
         break
    case 3:
        // http://sqyypttest.vankeservice.com:9000/p/web/serviceRequest
        vc = VKRepairOrderCtrl.init(weburl: "http://sqyypttest.vankeservice.com:9000/p/web/serviceRequest")
        break
    default:
        vc = nil
        break
    }
    if ((vc) != nil) {
        navigationController?.pushViewController(vc, animated: true)
    }
}

}

extension VKHomeViewCtrl:TYCyclePagerViewDataSource,TYCyclePagerViewDelegate{
func pagerViewTransformLayout(_ pagerViewTransformLayout: TYCyclePagerTransformLayout, initializeTransform attributes: UICollectionViewLayoutAttributes) {
Log(message: "呵呵呵")
}

func pagerViewTransformLayout(_ pagerViewTransformLayout: TYCyclePagerTransformLayout, applyTransformTo attributes: UICollectionViewLayoutAttributes) {
    Log(message: "哈哈哈")
}

func numberOfItems(in pageView: TYCyclePagerView) -> Int {
    return 1
}

func pagerView(_ pagerView: TYCyclePagerView, cellForItemAt index: Int) -> UICollectionViewCell {
    let cell = pagerView.dequeueReusableCell(withReuseIdentifier: "VKHomeCarouselCell", for: index)as!VKHomeCarouselCell
    cell.lab.text = String.init(format: "哈哈哈%d", index)
    return cell
}

func layout(for pageView: TYCyclePagerView) -> TYCyclePagerViewLayout {
    let layout = TYCyclePagerViewLayout.init()
    layout.itemSize = CGSize.init(width: ScreenWidth, height: 172 * kScreen)
    layout.itemHorizontalCenter = true
    return layout
}

}

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants