極客班測試題2

最近把第二次的習題整理了一下,并優化了一下懶加載圖片

做習題涉及和想到的點

我的習題代碼 Github

  • Lazy load image in table view: Apple example
    LazyTableImagesor or SDWebImage
  • Try NSURLSession
  • 望文生義的能力很重要
  • 拿到一個項目代碼,start step into from initial view,了解了整個 app 的運行時的結構或循環,才能理解整個 app 的邏輯框架。
  • 框架>目錄>類>方法>屬性/實例變量,這樣子下來整個一個 App 就跑起來了,入口就是 main.m,然后各種設置屬性和發消息,基于事件驅動的這一層理解運行時是比較合適的顆粒。
  • Lazy load iamge use AFNetworking
    [cell.appImage setImageWithURL:[NSURL URLWithString:[mediumImage valueForKeyPath:@"label"]] placeholderImage:[UIImage imageNamed:@"placeholder"]];

習題完成情況

第二題

完成 1.0:

  • 實現 table view 自帶刷新
  • 添加 Cellular 開關,并能夠檢查網絡連接方式,并提醒用戶
  • NSURLSession 下載 JSON

2015-08-26

進行中 1.1:

  • Lazy load iamge use AFNetworking

2015-09-03 11:36:32

Further Reading

  • 深入理解 RunLoop

    通過 Runloop 講解了 NSURLConnection 的工作過程
    iOS 中,關于網絡請求的接口自下至上有如下幾層:

CFSocket
CFNetwork       ->ASIHttpRequest
NSURLConnection ->AFNetworking
NSURLSession    ->AFNetworking2, Alamofire
  • CFSocket 是最底層的接口,只負責 socket 通信。

  • CFNetwork 是基于 CFSocket 等接口的上層封裝,ASIHttpRequest 工作于這一層。

  • NSURLConnection 是基于 CFNetwork 的更高層的封裝,提供面向對象的接口,AFNetworking 工作于這一層。

  • NSURLSession 是 iOS7 中新增的接口,表面上是和 NSURLConnection 并列的,但底層仍然用到了 NSURLConnection 的部分功能 (比如 com.apple.NSURLConnectionLoader 線程),AFNetworking2 和 Alamofire 工作于這一層。

  • Network Reachability Manager

    AFNetworkReachabilityManager monitors the reachability of domains, and addresses for both WWAN and WiFi network interfaces.

    Do not use Reachability to determine if the original request should be sent.
    You should try to send it.
    You can use Reachability to determine when a request should be automatically retried.
    Although it may still fail, a Reachability notification that the connectivity is available is a good time to retry something.
    Network reachability is a useful tool for determining why a request might have failed.
    After a network request has failed, telling the user they're offline is better than giving them a more technical but accurate error, such as "request timed out."

  • See also WWDC 2012 session 706, "Networking Best Practices.

  • SDWebImage

    AFNetworking takes advantage of Foundation URL Loading System caching using NSURLCache, as well as a configurable in-memory cache for UIImageView and UIButton, which uses NSCache by default. Caching behavior can be further specified in the caching policy of a corresponding NSURLRequest. Other SDWebImage features, like background decompression of image data is also provided by AFNetworking.

    If you're already using AFNetworking and just want an easy async image loading category, the built-in UIKit extensions will probably fit your needs.

  • AFNetworking example

    iOS example 非常經典,包含了使用方法和一個 UITableView實用框架。

  • AFNetworking 2.0 Tutorial

測試題原文

1. 做一個類似微信的聊天的 tableview(tablewviewcell 自定義) 。只需要 顯示文字內容和用戶頭像(不需要做輸入部分,文字內容自己模擬)

1 必須實現文字內容背景
2 背景的長度和高度要合適
3 發生者和接受者左右布局區分

2. 使用 http api 請求解析 json or xml 數據,并且使用 tableview 展示出來 http://ax.itunes.apple.com/WebObjects/MZStoreServices.woa/ws/RSS/toppaidapplications/limit=10/json or xml

提示:

  1. 可以使用第三方庫,也可以使用 SDK 基礎庫
  2. 顯示網絡下載數據時間
  3. 比較 xml or json 解析效率
  4. tableviewcell自定義

注:

  • 希望大家在一周內上傳答案到極客班 github 個人的作業文件夾(以學生編 號命名)
  • IOS 專業 Github 目錄: https://github.com/GeekBand/GeekBand-IOS-1501-Homework
  • 老師會在直播環節點評此題
  • 作業的最終批改和成績公布會在結業時進行。
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容