Skip to content

Commit

Permalink
Peek and pop links in the news list
Browse files Browse the repository at this point in the history
  • Loading branch information
weiran committed Jan 10, 2016
1 parent ce00f94 commit a3a7a95
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions Client/Post List/NewsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@ import Foundation
import UIKit
import SafariServices

class NewsViewController : UITableViewController, UISplitViewControllerDelegate, PostTitleViewDelegate, SFSafariViewControllerDelegate {
class NewsViewController : UITableViewController, UISplitViewControllerDelegate, PostTitleViewDelegate, SFSafariViewControllerDelegate, UIViewControllerPreviewingDelegate {

var posts: [HNPost] = [HNPost]()
private var collapseDetailViewController = true

override func viewDidLoad() {
super.viewDidLoad()
registerForPreviewingWithDelegate(self, sourceView: tableView)

tableView.estimatedRowHeight = 80
tableView.rowHeight = UITableViewAutomaticDimension // auto cell size magic
Expand Down Expand Up @@ -101,9 +102,27 @@ class NewsViewController : UITableViewController, UISplitViewControllerDelegate,

// MARK: - PostCellDelegate

func getSafariViewController(URL: String) -> SFSafariViewController {
return SFSafariViewController(URL: NSURL(string: URL)!)
}

func didPressLinkButton(post: HNPost) {
let safariViewController = SFSafariViewController(URL: NSURL(string: post.UrlString)!)
self.navigationController?.presentViewController(safariViewController, animated: true, completion: nil)
self.navigationController?.presentViewController(getSafariViewController(post.UrlString), animated: true, completion: nil)
UIApplication.sharedApplication().statusBarStyle = .Default
}

// MARK: - UIViewControllerPreviewingDelegate

func previewingContext(previewingContext: UIViewControllerPreviewing, viewControllerForLocation location: CGPoint) -> UIViewController? {
if let indexPath = tableView.indexPathForRowAtPoint(location) {
previewingContext.sourceRect = tableView.rectForRowAtIndexPath(indexPath)
let post = posts[indexPath.row]
return getSafariViewController(post.UrlString)
}
return nil
}

func previewingContext(previewingContext: UIViewControllerPreviewing, commitViewController viewControllerToCommit: UIViewController) {
presentViewController(viewControllerToCommit, animated: true, completion: nil)
}
}

0 comments on commit a3a7a95

Please sign in to comment.