Skip to content

Commit 8f6fee4

Browse files
Merge pull request #1 from JNDisrupter/fixingbugs
Fix bug when create view programmatically not from view or storyboard.
2 parents a47009c + db00ae3 commit 8f6fee4

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

JNHorizontalGroupAvatarCollectionView/JNHorizontalGroupAvatarCollectionView/JNHorizontalGroupAvatarCollectionView.swift

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -73,20 +73,6 @@ open class JNHorizontalGroupAvatarCollectionView: UIView, UICollectionViewDataSo
7373
*/
7474
override open func awakeFromNib() {
7575
super.awakeFromNib()
76-
77-
// Set collection data source and delegate
78-
self.collectionView.dataSource = self
79-
self.collectionView.showsHorizontalScrollIndicator = false
80-
81-
// Register cell
82-
let bundle = Bundle(for: AvatarCollectionViewCell.self)
83-
let nib = UINib(nibName: "AvatarCollectionViewCell", bundle: bundle)
84-
self.collectionView.register(nib, forCellWithReuseIdentifier: AvatarCollectionViewCell.getReuseIdentifier())
85-
86-
// Set collection ayout
87-
let layout = AvatarsCollectionViewFlowLayout()
88-
layout.cellPadding = self.cellPadding
89-
self.collectionView.collectionViewLayout = layout
9076
}
9177

9278
/**
@@ -110,6 +96,7 @@ open class JNHorizontalGroupAvatarCollectionView: UIView, UICollectionViewDataSo
11096
*/
11197
private func initView() {
11298

99+
// Bundle
113100
let bundle = Bundle(for: JNHorizontalGroupAvatarCollectionView.self)
114101
let nib = UINib(nibName: "JNHorizontalGroupAvatarCollectionView", bundle: bundle)
115102

@@ -124,6 +111,18 @@ open class JNHorizontalGroupAvatarCollectionView: UIView, UICollectionViewDataSo
124111
view.bottomAnchor.constraint(equalTo: self.bottomAnchor).isActive = true
125112
view.rightAnchor.constraint(equalTo: self.rightAnchor).isActive = true
126113
view.leftAnchor.constraint(equalTo: self.leftAnchor).isActive = true
114+
115+
// Set collection data source and delegate
116+
self.collectionView.dataSource = self
117+
self.collectionView.showsHorizontalScrollIndicator = false
118+
119+
// Register cell
120+
self.collectionView.register(UINib(nibName: "AvatarCollectionViewCell", bundle: bundle), forCellWithReuseIdentifier: AvatarCollectionViewCell.getReuseIdentifier())
121+
122+
// Set collection ayout
123+
let layout = AvatarsCollectionViewFlowLayout()
124+
layout.cellPadding = self.cellPadding
125+
self.collectionView.collectionViewLayout = layout
127126
}
128127
}
129128

0 commit comments

Comments
 (0)