当前位置:网站首页>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
边栏推荐
- How to make lamps intelligent? How to choose single fire and zero fire intelligent switches!
- Use com youth. banner. Solution to the inflateexception reported by the banner plug-in
- Clojure installation of metabase source code secondary development
- 【深入kotlin】 - 初识 Flow
- Slide the receleview horizontally to the far right to listen to the page loading function
- (15) Infrared communication
- 智能门锁为什么会这么火,米家和智汀的智能门锁怎么样呢?
- Méthode de la partie du tableau
- 安装Oracle数据库
- NDK learning notes (VII) system configuration, users and groups
猜你喜欢

More than 20 cloud collaboration functions, 3 minutes to talk through the enterprise's data security experience

AltiumDesigner2020导入3D Body-SOLIDWORKS三维模型

Multithreading tutorial (XXVII) CPU cache and pseudo sharing

Wechat applet learning record

What happened to the young man who loved to write code -- approaching the "Yao Guang young man" of Huawei cloud

Maximum number of points on the line ----- hash table solution

NDK learning notes (13) create an avi video player using avilib+opengl es 2.0

Implementation of data access platform scheme (Youzu network)

Analyze while doing experiments -ndk article -jni uses registernatives for explicit method registration

Redis setup (sentinel mode)
随机推荐
Activity start process record
Solution to slow connection speed of ojdbc under Linux system
Cocoapods installation error
Altiumdesigner2020 import 3D body SolidWorks 3D model
How to deal with message blackout and message sending failure of Aurora im
What happened to the young man who loved to write code -- approaching the "Yao Guang young man" of Huawei cloud
Maximum number of points on the line ----- hash table solution
Analysis while experiment - a little optimization of memory leakage in kotlin
Wxparse parsing iframe playing video
Aurora im live chat
Multi thread tutorial (XXIX) immutable design
Gilde failed to go to the listener to call back the reason record when loading the Gaussian blur image
Multithreading tutorial (XXVIII) unsafe class
Mingw-w64 installation instructions
Get the third-party interface
Xposed bypasses 360 reinforcement to get a real classloader
Multi threading tutorial (XXIV) cas+volatile
Array partial method
使用Batch设置IP地址
Méthode de la partie du tableau