SWIFTUITableView的基本用法

SWIFTUITableView的基本用法

2023年7月14日发(作者:)

SWIFTUITableView的基本⽤法import UIKit@UIApplicationMainclass AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { = UIWindow(frame: reen().bounds) // Override point for customization after application launch. !.backgroundColor = olor()

let navigation = UINavigationController(rootViewController: RootViewController()) ?.rootViewController = navigation

!.makeKeyAndVisible() return true }}import UIKitclass RootViewController: UIViewController { override func loadView() { ew() //初始化UITableView let tableView = UITableView() = reen().bounds urce = self te = self view(tableView) } //懒加载数据 lazy var datas:[String] = { return ["是⾬是泪","分分钟需要你","伤⼼太平洋","曾经最痛","飘雪"] }()

override func viewDidLoad() { dLoad() = "UITableView的基本⽤法" }}extension RootViewController:UITableViewDelegate,UITableViewDataSource{ //区的个数 func numberOfSectionsInTableView(tableView: UITableView) -> Int { return 1 } //在相应区中cell的个数 func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return } // cell的⾼度 func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat { return 60 }

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { //在重⽤机制⾥取出cell var cell = eReusableCellWithIdentifier("cell") //如果cell为空则创建 if cell == nil { cell = UITableViewCell(style: t, reuseIdentifier: "cell") } //设置数据 cell?.textLabel?.text = datas[] return cell! }

}

发布者:admin,转转请注明出处:http://www.yc00.com/xiaochengxu/1689265471a226468.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信