swift中cell的两种创建区别和extension的使用。让我们开发更有条理

swift中cell的两种创建区别和extension的使用。让我们开发更有条理,第1张

概述// //  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的使用。让我们开发更有条理所遇到的程序开发问题。

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

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1083849.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-27
下一篇 2022-05-27

发表评论

登录后才能评论

评论列表(0条)

保存