当前位置:网站首页>Swift tableview style (I) system basic
Swift tableview style (I) system basic
2022-07-05 10:09:00 【cppphp】
open Xcode, Create a new project :
choice iOS\Application\Single View Application
Create a single view application :
Set project name testTableView, Language choice Swift, Device selection Universal:
After the project is created , We can see in the project directory structure that there is only one storyboard
file :
Main.storyboard File is a general storyboard
file , It can adapt to all current screen sizes Apple Mobile devices . Open the file , You'll see a View Controller, And an interface dimension that we are not familiar with :
First , We turn on Main.storyboard
file , From component library (Object Library) Choose from Table View Drag and drop to View Controller in .
Select the just dragged Table View, add to 4 A constraint , Make it fill the screen .
then , Let's start from the component library (Object Library) Choose from Table View Cell And drag to Table View On .
Then select Basic, Enter basicCell.
Select Table View entry , Right click the mouse to pop up the black window below , Click the respectively dataSource and delegate The circle on the right , And drag to the position of the red arrow, and then release the mouse .
stay ViewContoler.swift Enter the following code
import UIKit
class ViewController: UIViewController,UITableViewDelegate,UITableViewDataSource {
var teststring: Array<String> = ["This is test1 of TabllView"]
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
// Data source method , How many groups are returned
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1;
}
// How many rows are there in each group
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return teststring.count
}
// What does each line show
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "basicCell", for: indexPath)
cell.textLabel?.text = teststring[indexPath.row]
return cell
}
}
Click on xcode The operation button in the upper left corner , The following screen will be displayed , A simple Table View It's done. .
Now let's add cell Dynamically add and delete function .
Let's add one at the bottom of the interface mentioned above View And put two buttons on it , Here's the picture
choice + Button and right-click to pop up the following black window , And then Touch Up Inside Press the left mouse button in the corresponding circle on the right and drag it to the red arrow , Releasing the right button will pop up the window at the bottom of the figure below Name Enter... In the input box addTest, In its Type Select... From the combo box UIButton, And then click Connect Button .
- The operation steps of the button are the same as + Button is the same. , The difference is just Name Enter... In the input box subTest, The others are the same .
And then again ..., It's the same old story , Let's see the following figure and operate by ourselves
The three red boxes in the figure below are dragged from above , Two of the drag buttons have function codes entered .
The completed code is as follows :
//
// ViewController.swift
// testTableView
//
// Created by xxxx on 2019/8/31.
// Copyright 2019 xxxxx. All rights reserved.
//
import UIKit
class ViewController: UIViewController,UITableViewDelegate,UITableViewDataSource {
var teststring: Array<String> = ["This is test1 of TabllView"]
@IBOutlet weak var vwTable: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
// Data source method , How many groups are returned
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1;
}
// How many rows are there in each group
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return teststring.count
}
// What does each line show
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "customCell", for: indexPath)
cell.textLabel?.text = teststring[indexPath.row]
return cell
}
@IBAction func addTest(_ sender: UIButton) {
let count = teststring.count + 1
teststring.append("This is test" + String(count) + " of TabllView")
vwTable.reloadData()
}
@IBAction func subTest(_ sender: UIButton) {
teststring.removeLast()
vwTable.reloadData()
}
}
Let's run the program again , adopt + and - Buttons can be added or deleted dynamically cell 了 , You can test .
边栏推荐
- Online chain offline integrated chain store e-commerce solution
- Application of data modeling based on wide table
- 宝塔面板MySQL无法启动
- Viewpager pageradapter notifydatasetchanged invalid problem
- 双容水箱液位模糊PID控制系统设计与仿真(Matlab/Simulink)
- From "chemist" to developer, from Oracle to tdengine, two important choices in my life
- Cross process communication Aidl
- 天龙八部TLBB系列 - 单体技能群伤
- 天龙八部TLBB系列 - 关于包裹掉落的物品
- Pagoda panel MySQL cannot be started
猜你喜欢
The popularity of B2B2C continues to rise. What are the benefits of enterprises doing multi-user mall system?
RMS TO EAP通过MQTT简单实现
Comment obtenir le temps STW du GC (collecteur d'ordures)?
MySQL字符类型学习笔记
如何正确的评测视频画质
写入速度提升数十倍,TDengine 在拓斯达智能工厂解决方案上的应用
【系统设计】指标监控和告警系统
[tips] get the x-axis and y-axis values of cdfplot function in MATLAB
.Net之延迟队列
观测云与 TDengine 达成深度合作,优化企业上云体验
随机推荐
The popularity of B2B2C continues to rise. What are the benefits of enterprises doing multi-user mall system?
正式上架!TDengine 插件入驻 Grafana 官网
How to implement complex SQL such as distributed database sub query and join?
把欧拉的创新带向世界 SUSE 要做那个引路人
How to use sqlcipher tool to decrypt encrypted database under Windows system
从“化学家”到开发者,从甲骨文到 TDengine,我人生的两次重要抉择
TDengine 已经支持工业英特尔 边缘洞见软件包
Solve the problem of no all pattern found during Navicat activation and registration
idea用debug调试出现com.intellij.rt.debugger.agent.CaptureAgent,导致无法进行调试
Apache DolphinScheduler 入门(一篇就够了)
Kotlin Compose 多个条目滚动
Mysql80 service does not start
Kotlin Compose 与原生 嵌套使用
RMS TO EAP通过MQTT简单实现
Unity粒子特效系列-毒液喷射预制体做好了,unitypackage包直接用 - 上
Are databases more popular as they get older?
RMS to EAP is simply implemented through mqtt
Roll up, break through 35 year old anxiety, and animate the CPU to record the function call process
(1) Complete the new construction of station in Niagara vykon N4 supervisor 4.8 software
Tianlong Babu TLBB series - questions about skill cooling and the number of attack ranges