Bir iOS uygulamasını hızlı bir şekilde yapıyorum ve bir koleksiyonView programlı olarak yapmaya çalışıyorum. UICollectionReusableView ürününün kendi alt sınıfını koleksiyon görünümü için bir başlık olarak kullanmak istiyorum çünkü bazı düğmelere ve üstbilgiye yapışan bir görüntüye ihtiyacım var.iOS; özel üstbilgilerle program aracılığıyla toplamaView
SupView, UICollectionReusableView'dir. Böyle, viewForSupplementaryElementOfKind
yılında Tamamlayıcı Görünüm eklemeye çalışıyorum ama başlık oluşturmak çalışırken bir hata alıyorum
override func viewDidLoad() {
super.viewDidLoad()
let layout = UICollectionViewFlowLayout()
layout.headerReferenceSize = CGSizeMake(self.view.frame.width, 200)
someView = SupView(frame: CGRectMake(0, 0, view.frame.width, 200))
collectionView = UICollectionView(frame: self.view.frame, collectionViewLayout: layout)
collectionView.delegate = self
collectionView.dataSource = self
collectionView.registerClass(UICollectionViewCell.self, forCellWithReuseIdentifier: "Cell")
collectionView.registerClass(UICollectionReusableView.self, forSupplementaryViewOfKind: UICollectionElementKindSectionHeader, withReuseIdentifier: "headerCell") // UICollectionReusableView
self.view.addSubview(collectionView)
}
:
func collectionView(collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, atIndexPath indexPath: NSIndexPath) -> UICollectionReusableView {
var reusableView : UICollectionReusableView? = nil
// Create header
if (kind == UICollectionElementKindSectionHeader) {
// Create Header
let headerView = collectionView.dequeueReusableSupplementaryViewOfKind(UICollectionElementKindSectionHeader, withReuseIdentifier: "headerCell", forIndexPath: indexPath) as! SupView
headerView.frame = CGRectMake(0, 0, view.frame.width, 200)
reusableView = headerView
}
return reusableView!
}
hata let headerView = ...
olduğunu ve diyor ki: "sinyal SIGABRT"
Headerview'ı nasıl başlatmalıyım, böylece akışımıma giriş yapabilirim? belki somewith
collectionView.registerClass(UICollectionReusableView.self, forSupplementaryViewOfKind: UICollectionElementKindSectionHeader, withReuseIdentifier: "headerCell")
ile ama hata bana verir SupView-sınıfı kaydetmek çalışırsanız:
.../collectionViewPlay/ViewController.swift:32:24: Cannot invoke 'registerClass' with an argument list of type '(SupView!, forSupplementaryViewOfKind: String, withReuseIdentifier: String)'
Herhangi Fikirler?
DÜZENLEME: alt sınıf uygulanması talep edildi
:
import UIKit
class SupView: UICollectionReusableView {
//////////////////////////////////////////////////////////////////////////////
override init(frame: CGRect) {
super.init(frame: frame)
self.myCustomInit()
}
//////////////////////////////////////////////////////////////////////////////
required init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)!
self.myCustomInit()
}
func myCustomInit() {
print("hello there from SupView")
}
}
SupView'in sınıf uygulamasını göster – Shoaib