mirror of
https://github.com/wahyd4/libr-ios.git
synced 2026-08-09 05:06:46 +10:00
85 lines
2.5 KiB
Swift
85 lines
2.5 KiB
Swift
// ExploreTableViewController.swift
|
|
//
|
|
// librx
|
|
//
|
|
// Created by Yunlong Zheng on 15/10/25.
|
|
// Copyright © 2015年 librx. All rights reserved.
|
|
//
|
|
|
|
import UIKit
|
|
|
|
class ExploreTableViewController: UITableViewController {
|
|
|
|
private var postsLoader = PostsLoader(.Default)
|
|
private var explores:[ExploreSource] = []
|
|
|
|
var dataUrl:String?
|
|
|
|
override func viewDidLoad() {
|
|
super.viewDidLoad()
|
|
// self.tableView.separatorColor = UIColor(red:240.0/255.0,
|
|
// green: 240.0/255.0, blue: 240.0/255.0,
|
|
// alpha: 0.0)
|
|
}
|
|
|
|
override func viewDidAppear(animated: Bool) {
|
|
super.viewDidAppear(animated)
|
|
|
|
|
|
|
|
refreshContent()
|
|
self.tableView.reloadData()
|
|
}
|
|
|
|
func refreshContent() {
|
|
loadPostsFromUrl(self.dataUrl!)
|
|
self.tableView.reloadData()
|
|
}
|
|
|
|
func loadPostsFromUrl(dataUrl: String) {
|
|
|
|
postsLoader.loadExploreSourcesFromUrl(url: dataUrl) { [weak self](sources) -> () in
|
|
if let selfView = self {
|
|
selfView.explores = sources
|
|
selfView.tableView.reloadData()
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
|
return explores.count
|
|
}
|
|
|
|
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
|
|
|
|
let source = explores[indexPath.row] as ExploreSource
|
|
let thumbnailUrl = NSURL(string: source.img)
|
|
|
|
let cellIdentifier = "Cell"
|
|
let cell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier, forIndexPath:indexPath) as! ExploreTableCell
|
|
|
|
cell.sourceTitle.text = source.title
|
|
cell.sourceTitle.lineBreakMode = NSLineBreakMode.ByWordWrapping
|
|
cell.sourceTitle.numberOfLines = 2
|
|
|
|
cell.sourceImg.sd_setImageWithURL(thumbnailUrl, placeholderImage: UIImage(named: "default"))
|
|
|
|
cell.sourceImg.layer.cornerRadius = cell.sourceImg.frame.size.width / 2
|
|
cell.sourceImg.clipsToBounds = true
|
|
cell.sourceImg.layer.borderWidth = 1
|
|
cell.sourceImg.layer.borderColor = UIColor.blackColor().CGColor
|
|
|
|
|
|
cell.descriptionLabel.text = source.description
|
|
|
|
//cell.sourceImg.layer.cornerRadius = cell.sourceTitle.frame.width / 2
|
|
//cell.sourceImg.clipsToBounds = true
|
|
|
|
return cell
|
|
|
|
}
|
|
|
|
|
|
}
|