Skip to content

Commit

Permalink
解决旧的API报错问题
Browse files Browse the repository at this point in the history
  • Loading branch information
xhzengAIB committed Nov 25, 2014
1 parent 57e8963 commit 93ff39c
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 34 deletions.
Binary file not shown.
32 changes: 16 additions & 16 deletions XHNewsParsingSwift/XHNewsParsingSwift/Base.lproj/Main.storyboard
@@ -1,20 +1,19 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="6154.17" systemVersion="13D65" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="AXJ-xB-8WG">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="6250" systemVersion="13F34" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" initialViewController="AXJ-xB-8WG">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="6153.11"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="6244"/>
</dependencies>
<scenes>
<!--News Table View Controller - News-->
<!--News-->
<scene sceneID="kdP-TT-ywF">
<objects>
<tableViewController id="aeQ-C8-dh0" customClass="XHNewsTableViewController" customModule="XHNewsParsingSwift" customModuleProvider="target" sceneMemberID="viewController">
<tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="80" sectionHeaderHeight="22" sectionFooterHeight="22" id="M9s-NE-FSR">
<rect key="frame" x="0.0" y="0.0" width="320" height="480"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<simulatedOrientationMetrics key="simulatedOrientationMetrics" orientation="landscapeRight"/>
<prototypes>
<tableViewCell contentMode="scaleToFill" ambiguous="YES" selectionStyle="default" accessoryType="disclosureIndicator" indentationWidth="10" reuseIdentifier="XHNewsCell" textLabel="xi2-Eg-vvn" detailTextLabel="W9g-LW-WWS" rowHeight="80" style="IBUITableViewCellStyleSubtitle" id="9q6-yq-bVU">
<tableViewCell contentMode="scaleToFill" selectionStyle="default" accessoryType="disclosureIndicator" indentationWidth="10" reuseIdentifier="XHNewsCell" textLabel="xi2-Eg-vvn" detailTextLabel="W9g-LW-WWS" rowHeight="80" style="IBUITableViewCellStyleSubtitle" id="9q6-yq-bVU">
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="9q6-yq-bVU" id="kUr-7H-6RM">
<autoresizingMask key="autoresizingMask"/>
Expand All @@ -34,7 +33,7 @@
</subviews>
</tableViewCellContentView>
<connections>
<segue destination="B88-XX-ZFQ" kind="show" identifier="showWebDetail" id="c4a-3r-VMG"/>
<segue destination="B88-XX-ZFQ" kind="push" identifier="showWebDetail" id="c4a-3r-VMG"/>
</connections>
</tableViewCell>
</prototypes>
Expand All @@ -47,27 +46,23 @@
</tableViewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="twx-VV-7RS" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="1048" y="343"/>
<point key="canvasLocation" x="736" y="324"/>
</scene>
<!--Web View Detail Controller - Detial-->
<!--Detial-->
<scene sceneID="S7o-Tw-0Ag">
<objects>
<viewController id="B88-XX-ZFQ" customClass="XHWebViewDetailController" customModule="XHNewsParsingSwift" customModuleProvider="target" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="lWp-RU-UG2"/>
<viewControllerLayoutGuide type="bottom" id="phF-Ct-pgI"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="D0s-nQ-Gu5">
<rect key="frame" x="0.0" y="0.0" width="320" height="480"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<webView contentMode="scaleToFill" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="Hgb-io-qNT">
<webView contentMode="scaleToFill" id="Hgb-io-qNT">
<rect key="frame" x="0.0" y="0.0" width="320" height="480"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
</webView>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<simulatedOrientationMetrics key="simulatedOrientationMetrics" orientation="landscapeRight"/>
</view>
<navigationItem key="navigationItem" title="Detial" id="rqT-X2-vet"/>
<connections>
Expand All @@ -77,7 +72,7 @@
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="12c-w9-o7j" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="1551" y="343"/>
<point key="canvasLocation" x="1230" y="324"/>
</scene>
<!--Navigation Controller-->
<scene sceneID="XWG-Lt-gOW">
Expand All @@ -97,7 +92,12 @@
</navigationController>
<placeholder placeholderIdentifier="IBFirstResponder" id="Nai-8f-DyE" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="510" y="343"/>
<point key="canvasLocation" x="272" y="324.70666666666665"/>
</scene>
</scenes>
<simulatedMetricsContainer key="defaultSimulatedMetrics">
<simulatedStatusBarMetrics key="statusBar"/>
<simulatedOrientationMetrics key="orientation"/>
<simulatedScreenMetrics key="destination" type="retina4"/>
</simulatedMetricsContainer>
</document>
Expand Up @@ -42,17 +42,18 @@ class XHNewsTableViewController : UITableViewController {
}

func loadDataSource() {
self.refreshControl.beginRefreshing()
var loadURL = NSURL.URLWithString(hackerNewsApiUrl)
var request = NSURLRequest(URL: loadURL)
self.refreshControl?.beginRefreshing()
var url: NSURL = NSURL(string: hackerNewsApiUrl)!

var request = NSURLRequest(URL: url)
var loadDataSourceQueue = NSOperationQueue();

NSURLConnection.sendAsynchronousRequest(request, queue: loadDataSourceQueue, completionHandler: { response, data, error in
if error {
if (error != nil) {
println(error)
dispatch_async(dispatch_get_main_queue(), {
self.refreshControl.endRefreshing()
})
// self.refreshControl?.endRefreshing()
})
} else {
let json = NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions.MutableContainers, error: nil) as NSDictionary
let newsDataSource = json["item"] as NSArray
Expand All @@ -69,7 +70,7 @@ class XHNewsTableViewController : UITableViewController {
dispatch_async(dispatch_get_main_queue(), {
self.dataSource = currentNewsDataSource
self.tableView.reloadData()
self.refreshControl.endRefreshing()
self.refreshControl?.endRefreshing()
})
}
})
Expand All @@ -78,11 +79,12 @@ class XHNewsTableViewController : UITableViewController {
// #pragma mark - Segues
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "showWebDetail" {
let indexPath = self.tableView.indexPathForSelectedRow()
let indexPath = self.tableView.indexPathForSelectedRow() as NSIndexPath!
let newsItem = dataSource[indexPath.row] as XHNewsItem
let webViewDetailController = segue.destinationViewController as XHWebViewDetailController!
webViewDetailController.detailID = newsItem.newsID
let controller = segue.destinationViewController as XHWebViewDetailController
controller.detailID = newsItem.newsID;
}

}


Expand All @@ -102,13 +104,16 @@ class XHNewsTableViewController : UITableViewController {
let newsItem = dataSource[indexPath.row] as XHNewsItem

cell.textLabel.text = newsItem.newsTitle
cell.detailTextLabel.text = newsItem.newsID
cell.detailTextLabel?.text = newsItem.newsID;
cell.imageView.image = UIImage(named :"cell_photo_default_small")
cell.imageView.contentMode = UIViewContentMode.ScaleAspectFit

let request = NSURLRequest(URL :NSURL.URLWithString(newsItem.newsThumb))
var url: NSURL = NSURL(string: newsItem.newsThumb)!


let request = NSURLRequest(URL :url)
NSURLConnection.sendAsynchronousRequest(request, queue: thumbQueue, completionHandler: { response, data, error in
if error {
if (error != nil) {
println(error)

} else {
Expand All @@ -123,7 +128,7 @@ class XHNewsTableViewController : UITableViewController {
return cell
}

override func tableView(tableView: UITableView!, heightForRowAtIndexPath indexPath: NSIndexPath!) -> CGFloat {
override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return 80
}

Expand Down
Expand Up @@ -14,7 +14,7 @@ class XHWebViewDetailController : UIViewController {

var detailURL = "http://qingbin.sinaapp.com/api/html/"

@IBOutlet var webView : UIWebView
@IBOutlet var webView : UIWebView?


override func viewDidLoad() {
Expand All @@ -29,8 +29,9 @@ class XHWebViewDetailController : UIViewController {

func loadDataSource() {
var urlString = detailURL + "\(detailID).html"
var url = NSURL.URLWithString(urlString)
var urlRequest = NSURLRequest(URL :NSURL.URLWithString(urlString))
webView.loadRequest(urlRequest)
var url: NSURL = NSURL(string: urlString)!

var urlRequest = NSURLRequest(URL :url)
webView?.loadRequest(urlRequest)
}
}

0 comments on commit 93ff39c

Please sign in to comment.