当前位置:网站首页>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
边栏推荐
- Multithreading tutorial (XXIII) thread safety without lock
- Exploration of kangaroo cloud data stack on spark SQL optimization based on CBO
- MySQL circulates multiple values foreach, XML writing method
- Multithreading tutorial (XXVIII) unsafe class
- Install Oracle Database
- Elk log system practice (VI): comparison between vector and filebeat for technology selection
- Multi threading tutorial (XXIV) cas+volatile
- Méthode de la partie du tableau
- How to deal with message blackout and message sending failure of Aurora im
- 初步了解多任务学习
猜你喜欢

YOLOv5的Tricks | 【Trick8】图片采样策略——按数据集各类别权重采样

What happened to the young man who loved to write code -- approaching the "Yao Guang young man" of Huawei cloud
![[metadata]linkedin datahub](/img/6a/247ee77dfc219d26651e5d93b04c98.png)
[metadata]linkedin datahub
![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

NFC Development -- the method of using NFC mobile phones as access control cards (II)

Start the project using the locally configured gradle

es-ik 安装报错

Big meal count (time complexity) -- leetcode daily question
![[元数据]LinkedIn-DataHub](/img/6a/247ee77dfc219d26651e5d93b04c98.png)
[元数据]LinkedIn-DataHub

“All in ONE”一个平台解决所有需求,运维监控3.0时代已来
随机推荐
Jsonobject jsonarray for parsing
Solution to slow connection speed of ojdbc under Linux system
NDK learning notes (IV) functions, classes and exceptions of swig
Flask develops and implements the like comment module of the online question and answer system
數組部分方法
Combination sum Ⅳ -- leetcode exercise
Convert result set of SQL to set
Adapter the problem of executing only one animation in multiple frames
Games101 job 7-path tracing implementation process & detailed interpretation of code
Mingw-w64 installation instructions
MinGW-W64安装说明
DISM命令使用小结
Wxparse parsing iframe playing video
PageHelper page 2 collections in the same interface
Fix Yum dependency conflict
MySQL string to array, merge result set, and convert to array
Multithreading tutorial (XXVI) field updater and atomic accumulator
27. Remove elements
AltiumDesigner2020导入3D Body-SOLIDWORKS三维模型
Preliminary understanding of multi task learning