我正在开发一个医疗账单应用程序,我有两个单元,用于两种不同类型的医疗代码。第一个是访问代码,第二个是诊断代码。可以有许多诊断代码被添加到特定的访问代码中,我试图使一个部分由一个单独的访问代码和任意数量的诊断代码(包括零)组成。
var icdCodes:[[(icd10:String,icd9:String)]] = [[]] //A list of diagnoses codes for the bill
var visitCodes:[String] = [] //A list of the visit codes that have been added目前,我有一个UICollectionView,我添加了访问代码。我在显示每个icd10单元的所有visitCode单元时遇到了问题。我可以排掉" ICD10Cell“的队列,但我不确定indexPath的单元格是visitCodeCell还是ICD10Cell。我的dataSource代码如下:
func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return icdCodes[section].count + 1 //add 1 for the initial visitcode cell
}
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("visitCodeCell", forIndexPath: indexPath) as! CodeTokenCollectionViewCell
cell.visitCodeLabel.text = visitCodes[indexPath.row]
cell.deleteCodeButton.tag = indexPath.row
return cell
}
func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
return visitCodes.count
}有人知道我怎样才能实现我想要的那种功能吗?
发布于 2015-07-06 20:09:37
对于可能有类似需求的人,我通过将访问代码作为头单元格并使用基于数据源的部分来解决我的问题。CollectionView方法如下:
func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
return visitCodes.count
}
func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return icdCodes[section].count
}
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("CONTENT", forIndexPath: indexPath) as! ICD10Cell
let sectionCodes:[(icd10:String, icd9:String)] = icdCodes[indexPath.section]
let (icd10String, icd9String) = sectionCodes[indexPath.row]
cell.ICDLabel.text = icd10String
return cell
}
func collectionView(collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, atIndexPath indexPath: NSIndexPath) -> UICollectionReusableView {
if kind == UICollectionElementKindSectionHeader {
let cell = collectionView.dequeueReusableSupplementaryViewOfKind(kind, withReuseIdentifier: "HEADER", forIndexPath: indexPath) as! CodeTokenCollectionViewCell
cell.visitCodeLabel.text = visitCodes[indexPath.section]
cell.deleteCodeButton.tag = indexPath.section
return cell
}
abort()
}如果不使用IB,则需要指定布局,并且需要在viewDidLoad()方法中指定标头大小。自定义单元格类也需要在viewDidLoad()方法中注册。
let layout = codeCollectionView.collectionViewLayout
let flow = layout as! UICollectionViewFlowLayout
flow.headerReferenceSize = CGSizeMake(100, 25)
codeCollectionView.registerClass(ICD10Cell.self, forCellWithReuseIdentifier: "CONTENT")
codeCollectionView.registerClass(CodeTokenCollectionViewCell.self, forSupplementaryViewOfKind: UICollectionElementKindSectionHeader, withReuseIdentifier: "HEADER")https://stackoverflow.com/questions/31211663
复制相似问题