swift 2
来源:互联网 发布:echo动作数据mmd 编辑:程序博客网 时间:2024/06/06 00:32
json 初级解析
已知返回数据格式
var imagearr :NSMutableArray!
var urlarr :NSMutableArray!
{ "state": true, "body": [ { "cover": "/images/push/201611/20161109093112_36.jpg", "id": 1, "type": 0, "content": "http://..............." }, { "cover": "/images/push/201611/20161109093127_313.jpg", "id": 2, "type": 0, "content": "http:/..............." }, { "cover": "/images/push/201611/20161109093141_286.jpg", "id": 3, "type": 0, "content": "http://..................." } ]}
func addData(){
let commen =comment()
imagearr =NSMutableArray()
urlarr =NSMutableArray()
// 调用oc的请求数据的方法 AnyObject是返回的json数据 如上 在block中进行解析
commen.getScrollViewPhotos { (AnyObject)in
let body = AnyObjectas?NSDictionary
let bodyArr = body?["body"]as?NSArray
for dicin bodyArr! {
let bodydic = dicas?NSDictionary
let imagestr = bodydic?["cover"]as!String
let urlstr = bodydic?["content"]as!String
imagearr.add(URLADDRESS+ imagestr)
urlarr.add(urlstr)
}
print(imagearr)
}
}
json 解析成model
model 文件是oc 文件 swift 进行调用
commen.getShouYeLanMu{(AnyObject)in
let body = AnyObjectas?NSDictionary
let bodyArr = body?["body"]as?NSArray
for dicin bodyArr! {
// 把字典转换成model的方法
let model =ShouYeLanMuModel(dic: dicas! [NSObject :AnyObject])
shouyelanmuArr.append(model!)
}
print(shouyelanmuArr)
}
设置导航栏的标题和返回按钮的颜色
self.navigationController?.navigationBar.isTranslucent = false // 导航栏不透明
self.navigationController?.navigationBar.tintColor = UIColor.orange // 返回按钮颜色
self.navigationController?.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName:UIColor.black]// 标题的颜色
创建右按钮
self.navigationItem.rightBarButtonItem =UIBarButtonItem(image:UIImage(named:"searchbutton"), style: .plain, target: self, action:#selector(searchAction))
func searchAction(){
let search =SearchViewController()
search.hidesBottomBarWhenPushed =true
self.navigationController?.pushViewController(search, animated: true)
}
collectionview 创建
let layout =UICollectionViewFlowLayout()layout.itemSize =CGSize(width:WIDTH/4.0,height:WIDTH/4.0 + 5*FITWIDTH)
layout.minimumLineSpacing =0
layout.minimumInteritemSpacing =0
headerCollectionView =UICollectionView(frame:CGRect(x:0,y:WIDTH*9/16,width:WIDTH,height:200),collectionViewLayout:layout)
headerCollectionView.delegate =self
headerCollectionView.dataSource =self
headerCollectionView.backgroundColor =UIColor.white
headerCollectionView.register(HeadTitleCollectionCell.self, forCellWithReuseIdentifier: “titleReuse”)
return1
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section:Int) ->Int {
return8
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath:IndexPath) ->UICollectionViewCell {
let titlecell = collectionView.dequeueReusableCell(withReuseIdentifier:"titleReuse", for: indexPath)
return titlecell
}
overrideinit(frame:CGRect){
super.init(frame: frame)
self.createView()
}
func createView(){
// 创建视图
}
requiredinit(coder aDecoder:NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
- swift 2
- swift(2)
- Swift 2
- swift-2
- swift --2
- Swift 2
- swift 2
- Swift源码分析----swift-proxy与swift-account(2)
- Swift源码分析----swift-proxy与swift-object(2)
- [openstack swift]1 swift安装(2)
- Swift源码分析----swift-account-audit(2)
- Swift源码分析----swift-object-auditor(2)
- Swift源码分析----swift-account-reaper(2)
- Swift源码分析----swift-account-replicator(2)
- Swift源码分析----swift-object-replicator(2)
- [openstack swift]2基本概念
- [openstack swift]2基本概念
- swift笔记(2)
- altium designer 怎么才能不经过原理图直接在空白pcb上加封装然后画线?
- sort
- Java 多线程之 Lock 的使用
- 枚举星期
- 获得微秒数 5
- swift 2
- hadoop集群调优及MR调优
- cacheimg 的使用
- v4l2 地址
- problems were encountered during export问题
- ORACLE SQL调优之统计信息缺失导致的逻辑读暴增
- Java环境配置与注意点
- mac java1.6怎么升到1.8
- install pip3 for python 3.x