Swift   发布时间:2022-03-31  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了swift中cell的两种创建区别和extension的使用。让我们开发更有条理大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

概述

// //  AppDelegate.swift //  WeiBo // //  Created by 胡双飞 on 15/10/4. //  Copyright © 2015年 HSF. All rights reserved. // import UIKit //MARK:定义cell注册问题 private let HomeCellIdentifier = "homeCell" class
// // AppDelegate.swift // WeiBo // // Created by 胡双飞 on 15/10/4. // Copyright © 2015年 HSF. All rights reserved. // import UIKit //MARK:定义cell注册问题 private let HomeCellIdentifier = "HomeCell" class HoMetableViewController: BaseTableViewController { override func viewDidLoad() { super.viewDidLoad() if !UserAccountviewmodel.shareUserAccount.isUserLogin{ visitorView?.setupInfo(nil,message: "关注一些人,回这里看看有什么惊喜") } loadData() tableView.registerClass(UITableViewCell.self,forCellReusEIDentifier: HomeCellIdentifier) } //加载数据 private func loadData(){ statusListviewmodel.loadStatus().subscribeError({ (error) -> Void in printLog(error) }) { () -> Void in self.tableView.reloadData() } } //MARK: - 懒加载 private lazy var statusListviewmodel = StatusListviewmodel() } //extension 类似于OC中的分类,扩展的意思。我们可以将uITableViewDatasource/UITabelTableViewDelegate放到这里更加清晰 extension HoMetableViewController{ //MARK:UITableViewController override func tableView(tableView: UITableView,numberOfRowsInSection section: int) -> Int { return statusListviewmodel.status?.count ?? 0 } override func tableView(tableView: UITableView,cellForRowATindexPath indexPath: NSIndexPath) -> UITableViewCell { //1 iOS5.0时 dequeueReusableCellWithIdentifier: 会查询可重用cell,如果有则拿来用,如果没有则创建一个。 //2 iOS6.0时 dequeueReusableCellWithIdentifier: forIndexPath:需要registerCell/storyboard/xib注册一个cell,,如果缓存区cell不存在,会使用cell实利化一个新的cell。 let cell = tableView.dequeueReusableCellWithIdentifier(HomeCellIdentifier,forIndexPath: indexPath) //1.获取微博数据 let status = statusListviewmodel.status![indexPath.item] as! Status cell.textLabel?.text = status.text return cell } }

大佬总结

以上是大佬教程为你收集整理的swift中cell的两种创建区别和extension的使用。让我们开发更有条理全部内容,希望文章能够帮你解决swift中cell的两种创建区别和extension的使用。让我们开发更有条理所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。