IOS学习-使用Alamofire和UICollectionView完成列表展示
2016-09-19 22:04
465 查看
直接代码吧
再简单的东西也要自己试一下
相关文章:
1. http://www.hangge.com/blog/cache/detail_968.html
2. http://www.jianshu.com/p/4acbf9632a5e
import UIKit import Alamofire import SwiftyJSON class ViewController: UIViewController,UICollectionViewDataSource, UICollectionViewDelegate { @IBOutlet weak var cv: UICollectionView! // 列表的数据,数组都是JSON类型的,这个是SwiftJSON的特点 var d = Array<JSON>() override func viewDidLoad() { super.viewDidLoad() let p = ["pageIndex" : 1, "pageSize" : 10, "value" : ""] // 获取列表的数据 Alamofire.request(.POST, "http://api.yourdomain.cn/api/Iqiyi/GetAlbumList", parameters: p).responseJSON() { res in if let data = res.result.value { var json = JSON(data) self.d = json["data"]["category"].arrayValue // 刷新列表 self.cv.reloadData() } } // 设置数据源和委托 self.cv.dataSource = self self.cv.delegate = self } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() } //列表的数量 func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { return self.d.count } // 构建cell func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell { let cell = cv.dequeueReusableCellWithReuseIdentifier("defaultCell", forIndexPath: indexPath) let label = cell.viewWithTag(10001) as! UILabel label.text = self.d[indexPath.item].string! return cell } // cell选中 func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) { print("\(self.d[indexPath.item])") } }
再简单的东西也要自己试一下
相关文章:
1. http://www.hangge.com/blog/cache/detail_968.html
2. http://www.jianshu.com/p/4acbf9632a5e
相关文章推荐
- iOS开发UI篇—使用嵌套模型完成的一个简单汽车图标展示程序
- iOS开发UI篇—使用UItableview完成一个简单的QQ好友列表(二)
- iOS开发UI篇—使用UItableview完成一个简单的QQ好友列表(一)
- iOS开发UI篇—使用UItableview完成一个简单的QQ好友列表(一)
- iOS开发UI篇—使用UItableview完成一个简单的QQ好友列表(一)
- iOS开发UI篇—使用UItableview完成一个简单的QQ好友列表(一)
- iOS开发UI基础—21使用嵌套模型完成的一个简单汽车图标展示程序
- iOS开发UI篇—使用UItableview完成一个简单的QQ好友列表(二)
- iOS开发学习笔记:使用xcode里的单元测试,放在STAssert…里面的语句无法使用自动完成功能
- iOS开发UI篇—使用嵌套模型完成的一个简单汽车图标展示程序
- iOS开发UI篇章使用UItableview完成一个简单的QQ好友列表(一)
- iOS开发UI篇—使用UItableview完成一个简单的QQ好友列表(二)
- iOS开发UI篇—使用UItableview完成一个简单的QQ好友列表(一)
- iOS开发UI篇—使用UItableview完成一个简单的QQ好友列表(一)
- iOS学习--列表下拉/上拉刷新: (一)EGORefreshTableHeaderView使用、定义EGORefreshTableFooterView
- iOS开发UI篇—使用UItableview完成一个简单的QQ好友列表(一)
- iOS开发UI篇—使用嵌套模型完成的一个简单汽车图标展示程序
- iOS开发UI篇—使用UItableview完成一个简单的QQ好友列表(一)
- iOS开发UI篇—使用UItableview完成一个简单的QQ好友列表(二)
- iOS开发UI篇—使用UItableview完成一个简单的QQ好友列表(二)