如果你總是將有7個細胞跨越視圖的頂部,只有7個細胞,老實說,我不會用一個UICollectionView
。 UICollectionView
當你有很多你需要能夠滾動的數據/圖像時,它真的很有光澤。相反,我會將這些「單元格」正常放置在水平StackView的內部(S127)。
然後,您可以給那些UIView的是爲挖掘姿勢目標的行動,其中更新和更改使用在與所需任務的底部在你的UITableView來填補你的DatSource。
至於與數據更新,使得以Date()
打電話會給設備的當前日期時間戳。您可以使用該對象的`.addingTimeInterval()'爲接下來的日子添加24,48等...小時。
編輯:
當然爲例,你提到你將有你的任務在數組中,你可以創建一個字典來保存任務的陣列的每一天,或數組的數組:var taskDictionary : [String : [Task]]?
或var taskArray : [[Task]]?
設置tapGesture的選擇,以將控制從詞典/陣列拉動內容的功能:
func dayOfWeekTapped(_ sender: UIView) {
myTableViewDataSource = taskDictionary[sender.tag]
//myTableViewDataSource = taskArray[sender.tag]
myTableView.reloadData()
}
我以前tag
財產這裏的一個例子,但這將是最好創建一個UIView子類,這樣你就可以訪問視圖中的UI元素:
func dayOfWeekTapped(_ sender: CustomUIView) {
myTableViewDataSource = taskDictionary[sender.dateLbl.text]
//myTableViewDataSource = taskArray[(sender.dateLabel.text as! NSString).intValue]
myTableView.reloadData()
}
我在想這個問題,並得到了好奇,但自定義的UIView可能看起來像這樣(非常快扔在一起,因此它可以被清理了一下):
protocol DayViewTappedDelegate {
func daySelected(_ selectedLabelText: String)
}
class DayView: UIView {
@IBOutlet var dateLbl: UILabel!
var tapGesture: UITapGestureRecognizer?
var delegate: DayViewTappedDelegate?
func setDelegateAndTap(_ delegate: DayViewTappedDelegate) {
self.delegate = delegate
self.tapGesture = UITapGestureRecognizer(target: self, action: #selector(self.dayViewTapped))
tapGesture?.numberOfTapsRequired = 1
self.addGestureRecognizer(tapGesture!)
}
@objc
func dayViewTapped() {
delegate!.daySelected(self.dateLbl.text!)
}
}
VC:
class ViewController: UIViewController, DayViewTappedDelegate {
@IBOutlet var dayBtns : [DayView]!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
for i in 0 ..< dayBtns.count {
let date = Date().addingTimeInterval(TimeInterval(86400 * i))
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "dd"
dayBtns[i].dateLbl.text = dateFormatter.string(from: date)
dayBtns[i].dateLbl.textAlignment = .center
dayBtns[i].setDelegateAndTap(self)
}
}
func daySelected(_ selectedLabelText: String) {
print(selectedLabelText)
}
}
你可以開始你結構模型設計擺脫隱含展開自選並使其PROPERT ies常量 –