当前位置:网站首页>Delegation agreement, data source agreement and advanced view in view
Delegation agreement, data source agreement and advanced view in view
2022-06-11 05:46:00 【swindler.】
Delegation agreement in view 、 Data source protocol and advanced view
Some advanced views have complex functions , We need to separate these complex functions from the view itself , Done by other classes . Of course , These classes need to follow the protocol specified by the view .
- Relatively simple views —— Only the entrustment agreement is specified , Include UITextField and UITextView, The corresponding naming rule of the delegation agreement is **“ View name +Delegate”**
- For some complex views , At the same time, we formulate the delegation agreement and data source agreement , These views are in iOS Not many , There are mainly selectors (UIPickerView)、 Collection view (UICollectionView) And table view (UItableView) The corresponding data source protocol naming rules are View name +DataSourse)
In the field of software , There is a classic saying :“ Where there is input , You need to verify ”
1. Selectors
import UIKit
class ViewController: UIViewController{
var datePicker:UIDatePicker!
var label:UILabel!
override func viewDidLoad() {
super.viewDidLoad()
let screen = UIScreen.main.bounds
self.view.backgroundColor = .clear
// Add date selector
let datePickerWidth:CGFloat = 320
let datePickerHeight:CGFloat = 167
self.datePicker = UIDatePicker(frame: CGRect(x: 0, y: 0, width: datePickerWidth, height: datePickerHeight))
// Set simplified Chinese
self.datePicker.locale = NSLocale(localeIdentifier: "zh-Hans") as Locale
// Format date and time
self.datePicker.datePickerMode = .dateAndTime
self.view.addSubview(datePicker)
// Add tags
let labelHeight:CGFloat = 200
let labelWidth:CGFloat = 21
let labelTopView:CGFloat = 281
self.label = UILabel(frame: CGRect(x: (screen.size.width - labelWidth)/2, y: labelTopView, width: labelWidth, height: labelHeight))
self.label.text = " Please select a date :"
self.label.textAlignment = .center
self.label.textColor = .white
self.view.addSubview(self.label)
// add to button Button
let button = UIButton(type: .system)
let buttonHeight:CGFloat = 46
let buttonWidth:CGFloat = 30
let buttonTopView:CGFloat = 379
button.frame = CGRect(x: (screen.size.width - buttonWidth)/2, y: buttonTopView, width: buttonWidth, height: buttonHeight)
button.setTitle(" choice ", for: UIControl.State())
button.addTarget(self, action: #selector(onClick(_:)), for: .touchUpInside)
self.view.addSubview(button)
}
@objc func onClick(_ sender:AnyObject){
let theDate:NSDate = self.datePicker.date as NSDate
// This property returns the selected time
let desc = theDate.description(with: NSLocale.current)
// This property returns localized date information
NSLog("the date picked is:%@", desc)// Log information
let dateFormatter:DateFormatter = DateFormatter()
dateFormatter.dateFormat = "YYYY-MM-dd HH:mm:ss"
NSLog("the date formate is :%@", dateFormatter.string(from: theDate as Date))// Log information
self.label.text = dateFormatter.string(from: theDate as Date)
}
}
2. Collection view
UICollecltionViewFlowLayout Is a streaming layout manager , From left to right, from top to bottom
边栏推荐
- 袋鼠雲數棧基於CBO在Spark SQL優化上的探索
- Utiliser le fichier Batch Enum
- 获取程序exit的值
- 20多种云协作功能,3分钟聊透企业的数据安全经
- Analyze while doing experiments -ndk article -jni uses registernatives for explicit method registration
- 创建酷炫的 CollectionViewCell 转换动画
- 初步了解多任务学习
- SQLite installation and configuration tutorial +navicat operation
- 22. Generate parentheses
- Games101 job 7-path tracing implementation process & detailed interpretation of code
猜你喜欢
![Yoyov5's tricks | [trick8] image sampling strategy -- Sampling by the weight of each category of the dataset](/img/54/f6a3e0ef1f77901506642784e6d3b7.png)
Yoyov5's tricks | [trick8] image sampling strategy -- Sampling by the weight of each category of the dataset

In the future, how long will robots or AI have human creativity?

Multithreading tutorial (XXVII) CPU cache and pseudo sharing

Error:Execution failed for task ':app:buildNative'. & gt; A problem occurred'x/x/x/'NDK build' error resolution

NFC Development -- difference between ID card and IC card (M1 card and CPU card) (III)

Altiumdesigner2020 import 3D body SolidWorks 3D model

es-ik 安装报错

MySQL string to array, merge result set, and convert to array

Write a list with kotlin

NDK learning notes (I)
随机推荐
Multithreading tutorial (XXVII) CPU cache and pseudo sharing
Clear function of ArrayList
NDK learning notes (12) native graphics API, using avilib to create an avi video player
Cocoapods installation error
Jsonobject jsonarray for parsing
“All in ONE”一个平台解决所有需求,运维监控3.0时代已来
MySQL string to array, merge result set, and convert to array
Slide the receleview horizontally to the far right to listen to the page loading function
NDK learning notes (14) create an avi video player using avilib+window
Get the full link address of the current project request URL
[go deep into kotlin] - flow advanced
Do we really need conference headphones?
Activity start process record
NDK learning notes (x) POSIX socket for connectionless communication
Why is the smart door lock so popular? What about the smart door locks of MI family and zhiting?
JS promise, async, await simple notes
getBackgroundAudioManager控制音乐播放(类名的动态绑定)
数据接入平台方案实现(游族网络)
Swap numbers (no temporary variables)
Recommend a free intranet penetration open source software that can be used in the local wechat official account under test