大佬教程收集整理的这篇文章主要介绍了iOS- UICollectionView 水平滚动 UITableView,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个 UItableVIEw,我在其中放置了一个 UICollectionVIEw,然后将此场景重用于 10 个或更多单元格。
我想要的是,当我滚动 UICollectionVIEw 时,其他集合视图的每个单元格也必须同时同步滚动。
@H_972_7@myVIEwController.swift
import UIKit
class VIEwController: UIVIEwController,UItableVIEwDelegate,UItableVIEwDatasource {
@IBOutlet private weak var menubutton: UIbutton!
@IBOutlet var dottedVIEw: UIVIEw!
var array1 = ["Indian Standard Time","AdelaIDe Standard Time","Auckland Standard Time","Melbourne Standard Time","Manchester Standard Time","Paris Standard Time","Alaska Standard Time","Greenland Standard Time","Sutherland Standard Time","Russia Standard Time"]
var array2 = ["desc","desc","desc"]
var array3 = ["Mon","Tue","Wed","Thu","Fri","Sat","Sun"]
var array4 = ["12 2021","12 2021","12 2021"]
func tableVIEw(_ tableVIEw: UItableVIEw,numberOfRowsInSection section: int) -> Int {
return 10
}
@IBOutlet var maintablevIEw: UItableVIEw!
func tableVIEw(_ tableVIEw: UItableVIEw,cellForRowAt indexPath: IndexPath) -> UItableVIEwCell {
let cell = tableVIEw.dequeueReusableCell(withIDentifIEr: "cell",for: indexPath) as! tableVIEwCell
cell.tag = indexPath.row
cell.collectionvIEw.tag = (100 * indexPath.section) + indexPath.row
cell.label1.text = array1[indexPath.row]
return cell
}
func tableVIEw(_ tableVIEw: UItableVIEw,heightForRowAt indexPath: IndexPath) -> CGfloat {
return 130
}
@IBACtion func datetiR_154_11845@eclick(_ sender: Any) {
let vc = storyboard?.instantiateVIEwController(IDentifIEr: "dateVIEwController") as! DateVIEwController
present(vc,animated: truE)
}
@IBACtion func addbtnclick(_ sender: Any) {
let vc = storyboard?.instantiateVIEwController(IDentifIEr: "timezonecontroller") as! TimeZoneVIEwController
present(vc,animated: truE)
}
overrIDe func vIEwDIDLoad() {
super.vIEwDIDLoad()
self.dottedVIEw.addDashedborder()
let nextdate = Date().addDate()
let prevdate = Date().subtractDate()
let dayofweek = String().dayOfWeek(fDate: nextdatE)
let tomorrowDate = String().dateOfWeek(fDate: nextdatE)
let yesterdayDate = String().dateOfWeek(fDate: prevdatE)
let year = String().getYear(fDate: Date())
let splitstr = dayofweek?.prefix(3)
print("tomdate",tomorrowDate!)
print("prevdate",yesterdayDate!)
print("year",year!)
print("dayofWeekCap",splitstr!)
menubutton.isUserInteractionEnabled = true
let interaction = UIContextMenuInteraction(delegate :self)
menubutton.BACkgroundcolor = UIcolor(hexString: "#1361E5")
menubutton.addInteraction(interaction)
}
overrIDe func vIEwDIDLayoutSubvIEws() {
}
}
import UIKit
class tableVIEwCell: UItableVIEwCell {
@IBOutlet weak var label1: UILabel!
@IBOutlet weak var label2: UILabel!
@IBOutlet weak var collectionvIEw: UICollectionVIEw!
@IBOutlet weak var collectioncell: UICollectionVIEwCell!
@IBOutlet weak var collectiontext: UILabel!
var scrollToposition = 0
var indexposition = 0
extension tableVIEwCell : UICollectionVIEwDelegate,UICollectionVIEwDatasource,UICollectionVIEwDelegateFlowLayout {
func collectionVIEw(_ collectionVIEw: UICollectionVIEw,numberOfItemsInSection section: int) -> Int {
return 48
}
func collectionVIEw(_ collectionVIEw: UICollectionVIEw,cellForItemAt indexPath: IndexPath) -> UICollectionVIEwCell {
let arrayString = timeSlot[indexPath.row]
let cell = collectionVIEw.dequeueReusableCell(withReusEIDentifIEr: "collectioncell",for: indexPath)
let title = UILabel(frame: CGRect(x: 0,y: 0,wIDth: 100,height: 33))
indexposition = indexPath.row
if indexPath.row >= scrollToposition
{
title.textcolor = UIcolor.white
cell.contentVIEw.BACkgroundcolor = UIcolor.systemBlue
}
else
{
title.textcolor = UIcolor.black
cell.layer.borderWIDth = 1.0
cell.layer.bordercolor = UIcolor.darkGray.cgcolor
cell.contentVIEw.BACkgroundcolor = UIcolor.white
}
title.text = arrayString
title.textAlignment = NSTextAlignment.center
for subVIEw in cell.contentVIEw.subvIEws {
subVIEw.removeFromSupervIEw()
}
cell.contentVIEw.addSubvIEw(titlE)
let Now = Date()
let formatter = DateFormatter()
formatter.locale = Locale(IDentifIEr: "en_IN")
formatter.dateFormat = "HH:mm" //for complete format EEEE dd MMMM YYYY HH:mm
let datetiR_154_11845@e = formatter.String(from: Now)
let currentDate = createDateFromString(String: datetiR_154_11845@E)
for i in timeSlot.inDices {
let arrayDate = createDateFromString(String: timeSlot[i])
if currentDate > arrayDate && flagDate == false {
flagDate = true
countToScroll = i
}
}
return cell
}
func collectionVIEw(_ collectionVIEw: UICollectionVIEw,layout collectionVIEwLayout: UICollectionVIEwLayout,sizeforItemAt indexPath: IndexPath) -> CGSize {
return CGSize(wIDth: 100,height: 33)
}
func scrollVIEwDIDScroll(_ scrollVIEw: UIScrollVIEw) {
dispatchQueue.main.async {
for cell in self.collectionvIEw.visibleCells {
let indexpath = self.collectionvIEw.indexPath(for: cell)
self.indexposition = indexpath!.row
self.collectionvIEw.SELEctItem(at: IndexPath(row: self.indexposition,section: 0),animated: true,scrollposition: .centeredHorizontally)
}
}
}
}
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)
以上是大佬教程为你收集整理的iOS- UICollectionView 水平滚动 UITableView全部内容,希望文章能够帮你解决iOS- UICollectionView 水平滚动 UITableView所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。