diff --git a/librx/ExploreTableViewController.swift b/librx/ExploreTableViewController.swift index 5e5e817..c05c927 100644 --- a/librx/ExploreTableViewController.swift +++ b/librx/ExploreTableViewController.swift @@ -52,17 +52,13 @@ class ExploreTableViewController: UITableViewController { override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { - let source = explores[indexPath.row] as ExploreSource - - let cellIdentifier = "Cell" - let cell = self.tableView.dequeueReusableCellWithIdentifier(cellIdentifier, forIndexPath:indexPath) as! ExploreTableCell - if (indexPath.row == self.explores.count-1) { self.loadMoreData() + return cellForLoadMore(cellForRowAtIndexPath: indexPath) + }else{ + return cellForRowsInSection(cellForRowAtIndexPath: indexPath) } - return cellForRowsInSection(source, cell: cell) - } override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { @@ -129,7 +125,34 @@ class ExploreTableViewController: UITableViewController { } - func cellForRowsInSection(source: ExploreSource, cell: ExploreTableCell) -> ExploreTableCell { + func cellForLoadMore(cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { + + let cell = UITableViewCell.init(style: UITableViewCellStyle.Default, reuseIdentifier: "moretag") + + let label = UILabel.init(frame: CGRectMake(0, 10, self.view.frame.width, 20)) + label.text = "加载更多" + label.backgroundColor = UIColor.clearColor() + label.textAlignment = .Center + label.font = label.font.fontWithSize(14.0) + label.tintColor = UIColor.blueColor() + + cell.contentView.addSubview(label) + + let activityView = UIActivityIndicatorView.init(frame: CGRectMake(0, 30 ,self.view.frame.width,30.0)) + activityView.activityIndicatorViewStyle = UIActivityIndicatorViewStyle.Gray + activityView.hidesWhenStopped = false + activityView.startAnimating() + + cell.contentView.addSubview(activityView) + return cell + } + + func cellForRowsInSection(cellForRowAtIndexPath indexPath: NSIndexPath) -> ExploreTableCell { + + let source = explores[indexPath.row] as ExploreSource + + let cellIdentifier = "Cell" + let cell = self.tableView.dequeueReusableCellWithIdentifier(cellIdentifier, forIndexPath:indexPath) as! ExploreTableCell let thumbnailUrl = NSURL(string: source.img) diff --git a/librx/StorysTableViewController.swift b/librx/StorysTableViewController.swift index 91e68c1..b0b66d0 100644 --- a/librx/StorysTableViewController.swift +++ b/librx/StorysTableViewController.swift @@ -31,6 +31,7 @@ class StorysTableViewController: UITableViewController { override func viewDidLoad() { super.viewDidLoad() + self.navigationController?.navigationBar.tintColor = UIColor.whiteColor() // mark: add refress control to tableview @@ -48,15 +49,6 @@ class StorysTableViewController: UITableViewController { self.tableView.rowHeight = UITableViewAutomaticDimension self.tableView.backgroundColor = UIColor(white: 0.97, alpha: 1) - // footer - let footerView = UIView.init(frame: CGRectMake(0, 0, 320, 70)) - let btn = UIButton.init(type: UIButtonType.RoundedRect) - btn.setTitle("加载更多", forState: .Normal) - btn.sizeToFit() - btn.titleLabel?.textAlignment = .Center - footerView.addSubview(btn) - //self.tableView.tableFooterView = footerView - // mark start refreshing self.refreshControl?.beginRefreshing() @@ -80,56 +72,23 @@ class StorysTableViewController: UITableViewController { } override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { - return posts.count + return posts.count + 1 } override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { - let post = posts[indexPath.row] as Post - - let cellIdentifier = "Cell" - let cell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier, forIndexPath:indexPath) as! CustomTableCell + if (indexPath.row == posts.count ){ - cell.delegate = self + return createLoadMoreTableCell(cellForRowAtIndexPath: indexPath) + + } else { + + return createNormalTableCell(cellForRowAtIndexPath: indexPath) - cell.nameLabel.text = post.title - cell.nameLabel.lineBreakMode = NSLineBreakMode.ByWordWrapping - cell.nameLabel.numberOfLines = 2 - - cell.summary.text = post.summary - cell.summary.lineBreakMode = NSLineBreakMode.ByWordWrapping - cell.summary.numberOfLines = 1 - - cell.readNumLabel.text = String(post.viewedTimes) - cell.likeNumLabel.text = String(post.likeCount) - cell.timeDiffLabel.text = DateUtil.timeDiff(post.getFormatCreateDateTime()) - - let avatarUrl = NSURL(string: post.firstSharer.avatar) - let thumbnailUrl = NSURL(string: post.thumbnail) - - if post.url.containsString("github") { - cell.thumbnilImageView.image = UIImage(named: "GitHub") - } else if post.url.containsString("zhihu"){ - cell.thumbnilImageView.image = UIImage(named: "zhihu") - }else{ - cell.thumbnilImageView.sd_setImageWithURL(thumbnailUrl, placeholderImage: UIImage(named: "default")) } - cell.thumbnilImageView.layer.cornerRadius = 6 - cell.thumbnilImageView.clipsToBounds = true - cell.thumbnilImageView.layer.borderWidth = 1 - cell.thumbnilImageView.layer.borderColor = UIColor.clearColor().CGColor - - cell.avatarImageView.sd_setImageWithURL(avatarUrl, placeholderImage: UIImage(named: "default")) - cell.avatarImageView.layer.cornerRadius = cell.avatarImageView.frame.size.width / 2 - cell.avatarImageView.clipsToBounds = true - - cell.nameButton.tag = post.firstSharer.id - - cell.shareNameLabel.text = post.firstSharer.name - - return cell } + override func numberOfSectionsInTableView(tableView: UITableView) -> Int { @@ -195,7 +154,76 @@ class StorysTableViewController: UITableViewController { } } + func createLoadMoreTableCell(cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { + + let cell = UITableViewCell.init(style: UITableViewCellStyle.Default, reuseIdentifier: "moretag") + + let label = UILabel.init(frame: CGRectMake(0, 10, self.view.frame.width, 20)) + label.text = "加载更多" + label.backgroundColor = UIColor.clearColor() + label.textAlignment = .Center + label.font = label.font.fontWithSize(14.0) + label.tintColor = UIColor.blueColor() + + cell.contentView.addSubview(label) + + let activityView = UIActivityIndicatorView.init(frame: CGRectMake(0, 30 ,self.view.frame.width,30.0)) + activityView.activityIndicatorViewStyle = UIActivityIndicatorViewStyle.Gray + activityView.hidesWhenStopped = false + activityView.startAnimating() + + cell.contentView.addSubview(activityView) + return cell + + } + func createNormalTableCell(cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell{ + + let post = posts[indexPath.row] as Post + + let cellIdentifier = "Cell" + let cell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier, forIndexPath:indexPath) as! CustomTableCell + + cell.delegate = self + + cell.nameLabel.text = post.title + cell.nameLabel.lineBreakMode = NSLineBreakMode.ByWordWrapping + cell.nameLabel.numberOfLines = 2 + + cell.summary.text = post.summary + cell.summary.lineBreakMode = NSLineBreakMode.ByWordWrapping + cell.summary.numberOfLines = 1 + + cell.readNumLabel.text = String(post.viewedTimes) + cell.likeNumLabel.text = String(post.likeCount) + cell.timeDiffLabel.text = DateUtil.timeDiff(post.getFormatCreateDateTime()) + + let avatarUrl = NSURL(string: post.firstSharer.avatar) + let thumbnailUrl = NSURL(string: post.thumbnail) + + if post.url.containsString("github") { + cell.thumbnilImageView.image = UIImage(named: "GitHub") + } else if post.url.containsString("zhihu"){ + cell.thumbnilImageView.image = UIImage(named: "zhihu") + }else{ + cell.thumbnilImageView.sd_setImageWithURL(thumbnailUrl, placeholderImage: UIImage(named: "default")) + } + cell.thumbnilImageView.layer.cornerRadius = 6 + cell.thumbnilImageView.clipsToBounds = true + cell.thumbnilImageView.layer.borderWidth = 1 + cell.thumbnilImageView.layer.borderColor = UIColor.clearColor().CGColor + + cell.avatarImageView.sd_setImageWithURL(avatarUrl, placeholderImage: UIImage(named: "default")) + cell.avatarImageView.layer.cornerRadius = cell.avatarImageView.frame.size.width / 2 + cell.avatarImageView.clipsToBounds = true + + cell.nameButton.tag = post.firstSharer.id + + cell.shareNameLabel.text = post.firstSharer.name + + return cell + + } @IBAction func startSharePost() {