日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

【swift学习笔记】三.使用xib自定义UITableViewCell

發(fā)布時間:2023/11/29 编程问答 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【swift学习笔记】三.使用xib自定义UITableViewCell 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

使用xib自定義tableviewCell看一下效果圖

1.自定義列

新建一個xib文件 carTblCell,拖放一個UITableViewCell,再拖放一個圖片和一個文本框到tableviewcell上

并給我們的xib一個標(biāo)識

為了學(xué)習(xí),我這里的xib和后臺的class是分開建的。我們再建一個cocoa touch class文件名稱為CarCellTableViewCell繼承自UITableViewCell

并把我們的xib和新建的CarCellTableViewCell建立聯(lián)接

?

在CarCellTableViewCell里建立和xib的圖片和文本框的輸出

import UIKitclass CarCellTableViewCell: UITableViewCell {@IBOutlet weak var cellImg: UIImageView!@IBOutlet weak var lbCell: UILabel!override func awakeFromNib() {super.awakeFromNib()// Initialization codecellImg.layer.borderWidth = 1cellImg.layer.masksToBounds = true//cellImg.layer.cornerRadius = 31 }override func setSelected(selected: Bool, animated: Bool) {super.setSelected(selected, animated: animated)// Configure the view for the selected state }}

?

2.關(guān)聯(lián)cell和tableview

1. 在main.storyboard上拖放一個uitableview,并在后臺代碼建立輸出聯(lián)接

1.在load事件里注冊xib

2.在tableveiw的方法里得到當(dāng)前的列,指定數(shù)據(jù)源。

import UIKitclass ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {@IBOutlet var tableView: UITableView!var tableData: [String] = ["BMW", "Ferrari", "Lambo"]override func viewDidLoad() {super.viewDidLoad()// Do any additional setup after loading the view, typically from a nib.let cellNib = UINib(nibName: "carTblCell", bundle: nil)tableView.registerNib(cellNib, forCellReuseIdentifier: "cell")}override func didReceiveMemoryWarning() {super.didReceiveMemoryWarning()// Dispose of any resources that can be recreated. }func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {return tableData.count}func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {let cell: CarCellTableViewCell = self.tableView.dequeueReusableCellWithIdentifier("cell") as! CarCellTableViewCellcell.lbCell.text = tableData[indexPath.row]cell.cellImg.image = UIImage(named: tableData[indexPath.row])return cell}func tableView(tableView: UITableView, didDeselectRowAtIndexPath indexPath: NSIndexPath) {print("\(indexPath.row)")}func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {return 70} } 本文轉(zhuǎn)自lpxxn博客園博客,原文鏈接:http://www.cnblogs.com/li-peng/p/5543415.html,如需轉(zhuǎn)載請自行聯(lián)系原作者
創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎勵來咯,堅持創(chuàng)作打卡瓜分現(xiàn)金大獎

總結(jié)

以上是生活随笔為你收集整理的【swift学习笔记】三.使用xib自定义UITableViewCell的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。