开发一个应用程序以创建学校时间表。 https://github.com/brightec/CustomCollectionViewLayout 使用此github源代码完成我的设计。
我的代码:
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: contentCellIdentifier,
for: indexPath) as! MyCollectioViewCell
cell.contentLabel.text = ""
if indexPath.section % 2 != 0 {
cell.backgroundColor = UIColor(white: 242/255.0, alpha: 1.0)
} else {
cell.backgroundColor = UIColor.white
}
if indexPath.section == 0 {
if indexPath.row == 0 {
cell.contentLabel.text = "Period.No"
} else {
cell.contentLabel.text = ""
cell.contentLabel.text = "\(indexPath.row)"
}
} else {
if indexPath.row == 0 {
if self.sectionArr.count == 2
{
dayArr = ["","MONDAY"]
cell.contentLabel.text = dayArr[indexPath.section] as? String
}
else if self.sectionArr.count == 3
{
dayArr = ["","MONDAY","TUESDAY"]
cell.contentLabel.text = dayArr[indexPath.section] as? String
}
else if self.sectionArr.count == 4
{
dayArr = ["","MONDAY","TUESDAY","WEDNESDAY"]
cell.contentLabel.text = dayArr[indexPath.section] as? String
}
else if self.sectionArr.count == 5
{
dayArr = ["","MONDAY","TUESDAY","WEDNESDAY","THURSDAY"]
cell.contentLabel.text = dayArr[indexPath.section] as? String
}
else if self.sectionArr.count == 6
{
dayArr = ["","MONDAY","TUESDAY","WEDNESDAY","THURSDAY","FRIDAY"]
cell.contentLabel.text = dayArr[indexPath.section] as? String
}
else if self.sectionArr.count == 7
{
dayArr = ["","MONDAY","TUESDAY","WEDNESDAY","THURSDAY","FRIDAY","SATURDAY"]
cell.contentLabel.text = dayArr[indexPath.section] as? String
}
} else {
//cell.contentLabel.text = "\([indexPath.section])\([indexPath.row])"
cell.classBtn.tag = indexPath.row
cell.classBtn.tag = indexPath.section
cell.classBtn.addTarget(self, action: #selector(self.yourFunc), for: .touchUpInside)
print("section",[indexPath.section])
print("row>>",[indexPath.row])
print("< loaded")
}
}
return cell
}
@objc func yourFunc(sender : UIButton){
print(sender.tag)
let dropBtn = sender as UIButton
classtypeDropDown.anchorView = dropBtn
classtypeDropDown.bottomOffset = CGPoint(x: 0, y: dropBtn.bounds.height)
classtypeDropDown.dataSource = self.subject_list_timeTable.value(forKey:"subject_name") as! [String]
classtypeDropDown.selectionAction = {(index, item) in
self.subject_id_Timetable = self.subjectidArr_timeTable[index] as! String
print("subject_id_Timetable",self.subject_id_Timetable)
self.subject_name_StrTimetable = item
print(index)
self.indexValueAddedArr.add(index)
print("indexValueAddedArr",self.indexValueAddedArr)
print(item)
dropBtn.setTitle(item,for: .normal)
}
classtypeDropDown.show()
}
1)在uicollectionview中创建一个按钮,选择并在collectionview中添加值,使用下拉按钮单击通过Webservies加载的主题。值添加到uicollectionview中,但滚动收集视图示例值在所有单元格中重复,如何解决此问题,我的代码在上面。
2)天是静态的6天。但是周期是动态的,用户可以给出周期数。如何获取n个周期值并传递给网络服务。
期间应为用户定义的'n'号。 如何获取每个行和节的值并存储在数组中并发送到Webservies。按钮点击操作 func yourFunc(sender:UIButton)在上述代码中显示。想要在uicollection视图中获取所有用户定义的数字值,并将其与每个行和节一起存储在数组中。 如何实现帮助我难以实现。