// // AppDelegate.swift // WeiBo // // Created by 胡双飞 on 15/10/4. // Copyright © 2015年 HSF. All rights reserved. // import UIKit //MARK:定义cell注册问题 private let HomeCellIdentifier =
// // AppDelegate.swift // WeiBo // // Created by 胡双飞 on 15/10/4. // Copyright © 2015年 HSF. All rights reserved. // import UIKit //MARK:定义cell
注册问题 private let HomeCellIdentifier = "HomeCell" class Ho
MetableViewController: BaseTableViewController
{ override func viewDidLoad()
{ super.viewDidLoad() if !UserAccount
viewmodel.shareUserAccount.isUserLogin
{ visitorView?.setupInfo(nil,
message: "关注一些人,回这里看看有什么惊喜") } loadData() tableView.registerClass(UITableViewCel
l.self,forCellReus
EIDentifier: HomeCellIdentifier) } //加载数据 private func loadData()
{ statusList
viewmodel.loadStatus().subscribeError(
{ (error) -> Void in printLog(error) })
{ () -> Void in self.tableView.reloadData() } } //MARK: - 懒加载 private lazy var statusList
viewmodel = StatusList
viewmodel() } //extension 类似于OC中的
分类,扩展的意思。我们可以
将uITableViewData
source/UITabelTableViewDelegate放到这里更加清晰 extension Ho
MetableViewController
{ //MARK:UITableViewController override func tableView(tableView: UITableView,
numberOfRowsInSection section:
int) -> Int
{ return statusList
viewmodel.status?.count ?? 0 } override func tableView(tableView: UITableView,cellForRowA
TindexPath 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 = statusList
viewmodel.status![indexPath.item] as! Status cel
l.textLabel?.text = statu
s.text return cell } }