1
程序员文章站
2024-03-21 19:46:34
...
import UIKit
class CellData: NSObject {
static func getCellData() -> [QQModel]{
let arr1 = ["ThinkCMF模板交流群","iOS-VIP学习群","Androidsik","我的电脑","iOS技术攻坚","淘宝达人VIP群","QQ手游","移动通信学院总成员","QQ看点"]
let arr2 = ["Maps:你那个手指疼","iOS果果老师:杭州首推","崔亚鹏:666","[图片]IMG_1725.PNG","郭胜成撤回了一条消息","99 老盘:达人转行做个了?","七夕领紫色亚丝娜&限定皮肤","行政干事-徐芳:请通知大数据1609G移动1610E苹...","[热议]强强联合!马云携手VIVO,开启支付新..."]
let arr3 = ["下午2:35","下午2:35","下午2:35","下午2:35","下午2:35","下午2:35","下午2:35","下午2:35","下午2:35"]
let imageName = ["07","07","07","07","07","07","07","07","07"]
var mArr:[QQModel] = []
for i in 0..<arr1.count{
let md = QQModel(imgV: imageName[i], Zhu: arr1[i], Fu: arr2[i], Time: arr3[i])
mArr.append(md)
}
return mArr
}
}
import UIKit
class QQModel: NSObject {
var imgV : String
var Zhu : String
var Fu : String
var Time : String
init(imgV:String,Zhu:String,Fu:String,Time:String) {
self.imgV = imgV
self.Zhu = Zhu
self.Fu = Fu
self.Time = Time
}
}
import UIKit
class QQTableViewCell: UITableViewCell {
@IBOutlet weak var picImageView: UIImageView!
@IBOutlet weak var ZhuLabel: UILabel!
@IBOutlet weak var FuLabel: UILabel!
@IBOutlet weak var TimeLabel: UILabel!
func setCellWithData(model:QQModel) -> Void {
self.ZhuLabel.text = model.Zhu
self.FuLabel.text = model.Fu
self.TimeLabel.text = model.Time
self.picImageView?.image = UIImage(named: model.imgV)
picImageView?.layer.masksToBounds = true
picImageView?.layer.cornerRadius = 35
}
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}
override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
// Configure the view for the selected state
}
}
mport UIKit
class OneViewController: UIViewController , UITableViewDelegate , UITableViewDataSource{
var mArr:[QQModel] = CellData.getCellData()
override func viewDidLoad() {
super.viewDidLoad()
// 设置导航标题
self.navigationItem.title = "消息"
// 设置导航背景颜色
self.navigationController?.navigationBar.barTintColor = UIColor.init(red: 123/255.0, green: 176/255.0, blue: 244/255.0, alpha: 1.0)
// 设置导航栏标题的字体颜色
self.navigationController?.navigationBar.titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.white, NSAttributedString.Key.font: UIFont.systemFont(ofSize: 20)]
// 设置导航右边按钮图片
let rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: UIBarButtonItem.SystemItem.add, target: self, action: #selector(rightClick))
navigationItem.rightBarButtonItem = rightBarButtonItem
// 设置左边按钮
// 设置表格
let table = UITableView(frame: self.view.frame, style: .plain)
// 设置代理
table.delegate = self
table.dataSource = self
// 加载到视图中
self.view .addSubview(table)
table.register(UINib(nibName: "QQTableViewCell", bundle: Bundle.main), forCellReuseIdentifier: "cell")
// 设置搜索框
let sear = UISearchBar(frame: CGRect(x: 0, y: 0, width: self.view.frame.size.width, height: 44))
sear.placeholder = "搜索"
table.tableHeaderView = sear
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 9
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell:QQTableViewCell = tableView.dequeueReusableCell(withIdentifier: "cell") as! QQTableViewCell
let md:QQModel = mArr[indexPath.row]
cell.setCellWithData(model: md)
return cell
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 90
}
// 设置点击事件
@objc private func rightClick() {
let two = TwoViewController()
self.navigationController!.pushViewController(two, animated: true)
}
}
上一篇: 1
推荐阅读
-
打印出 1 - 10000 之间的所有对称数,例如 121、1331 等
-
1
-
1
-
1
-
1
-
Refactoring Day 1 : Encapsulate Collection
-
java.sql.SQLException: Parameter index out of range (1 > number of parameters, w 博客分类: java细节
-
【杂文】开发者从工具更新到工具规划(1)-------MySQL5.7免安装版配置
-
1、MySQL安装,版本MySQL Community Server 8.0.22
-
Java自学之路-Java基础教程-1:第一行Java代码Hello World!