Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 未调用UICollectionViewDelegate和UICollectionViewDataSource方法_Ios_Swift_Uicollectionview - Fatal编程技术网

Ios 未调用UICollectionViewDelegate和UICollectionViewDataSource方法

Ios 未调用UICollectionViewDelegate和UICollectionViewDataSource方法,ios,swift,uicollectionview,Ios,Swift,Uicollectionview,我正在使用内部有UICollectionView的UITableViewCell。使用此结构,一切都能完美工作: class PostCell: UITableViewCell, UICollectionViewDelegate, UICollectionViewDataSource {} 但是,当我开始将UICollectionViewDelegate和UICollectionViewDataSource提取到另一个类时 class PostCell: UITableViewCell {

我正在使用内部有UICollectionView的UITableViewCell。使用此结构,一切都能完美工作:

class PostCell: UITableViewCell, UICollectionViewDelegate, UICollectionViewDataSource {}
但是,当我开始将UICollectionViewDelegate和UICollectionViewDataSource提取到另一个类时

class PostCell: UITableViewCell {
    @IBOutlet weak var collectionView: UICollectionView!

    public func populate(users: [User]) {
        UsersManager(users: users, collectionView: collectionView)
    }
}
public class UsersManager: NSObject, UICollectionViewDelegate, UICollectionViewDataSource {
    private var users: [User]!
    private var collectionView: UICollectionView!

    init(users: [User], collectionView: UICollectionView) {
        super.init()

        let nib = UINib(nibName: UserCell.IDENTIFIER, bundle:nil)
        collectionView.register(nib, forCellWithReuseIdentifier: UserCell.IDENTIFIER)
        collectionView.delegate = self
        collectionView.dataSource = self

        collectionView.reloadData()
    }
}
不调用委托方法

collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell
collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int
numberOfSections(in collectionView: UICollectionView) -> Int
我正在将collectionView传递给UsersManager。 我给两个都打电话:

collectionView.delegate = self
collectionView.dataSource = self 
在UsersManager中


您认为这里的问题是什么?

您在哪里创建实例UsersManager?您应该有UsersManagerUpdated my@karthikeyan的实例。谢谢你的帮助=我怀疑NSObject类要求您编码和解码,检查此链接您的目标通过使用UIView以相同的方式实现。
class PostCell: UITableViewCell {
    @IBOutlet weak var collectionView: UICollectionView!

    var usersManager:UsersManager?  // add this line.

    public func populate(users: [User]) {
        usersManager = UsersManager(users: users, collectionView: collectionView)
    }
}