import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {// Override point for customization after application launch.//底部标签控制器let oneNav = UINavigationController(rootViewController: OneVC())oneNav.tabBarItem = UITabBarItem(title: "首页", image: UIImage(named: "dongTai"), selectedImage: UIImage(named: "dongTai_H"))let twoNav = UINavigationController(rootViewController: VCTwo())twoNav.tabBarItem = UITabBarItem(title: "微淘", image: UIImage(named: "dongTai"), selectedImage: UIImage(named: "dongTai_H"))let threeNav = UINavigationController(rootViewController: ThreeVC())threeNav.tabBarItem = UITabBarItem(title: "消息", image: UIImage(named: "dongTai"), selectedImage: UIImage(named: "dongTai_H"))let fourNav = UINavigationController(rootViewController: FourVC())fourNav.tabBarItem = UITabBarItem(title: "购物车", image: UIImage(named: "dongTai"), selectedImage: UIImage(named: "dongTai_H"))let fiveNav = UINavigationController(rootViewController: FiveVC())fiveNav.tabBarItem = UITabBarItem(title: "我的", image: UIImage(named: "dongTai"), selectedImage: UIImage(named: "dongTai_H"))let tbv = UITabBarController()tbv.viewControllers = [oneNav,twoNav,threeNav,fourNav,fiveNav]tbv.selectedViewController = twoNavwindow?.rootViewController = tbvreturn true
}func applicationWillResignActive(_ application: UIApplication) {// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.// Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
}func applicationDidEnterBackground(_ application: UIApplication) {// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}func applicationWillEnterForeground(_ application: UIApplication) {// Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
}func applicationDidBecomeActive(_ application: UIApplication) {// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}func applicationWillTerminate(_ application: UIApplication) {// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

}

import UIKit

class VCTwo: UIViewController {

private lazy var pageTitleView: MFPageTitleView = {let config = MFPageTitleViewConfig()config.titleColor = colorWithRGB(r: 43, g: 43, b: 43)config.titleSelectedColor = colorWithRGB(r: 211, g: 0, b: 0)config.titleFont = UIFont.systemFont(ofSize: 14, weight: .regular)config.indicatorColor = colorWithRGB(r: 211, g: 0, b: 0)let pageTitleView = MFPageTitleView(frame: CGRect(x: 0, y: navHeight, width: SCREEN_WIDTH, height: 41), titles: ["全部", "上新", "视频直播", "特别关注", "达人"], config: config)pageTitleView.pageTitleViewDelegate = selfreturn pageTitleView
}()private lazy var pageContentView: MFPageContentView = {var childControllers = [UIViewController]()for k in 0..<5 {var vc = UIViewController()let red: CGFloat = CGFloat(arc4random() % 256)let green: CGFloat = CGFloat(arc4random() % 256)let blue: CGFloat = CGFloat(arc4random() % 256)vc.view.backgroundColor = UIColor(red: red / 255.0, green: green / 255.0, blue: blue / 255.0, alpha: 1.0)if k==4{vc = WeiTaoVC()}childControllers.append(vc)}let pageContentViewY = pageTitleView.frame.maxYlet pageContentView = MFPageContentView(frame: CGRect(x: 0, y: pageContentViewY, width: SCREEN_WIDTH, height: SCREEN_HEIGHT-pageContentViewY), parentVC: self, childVCs: childControllers)pageContentView.pageContentViewDelegate = selfreturn pageContentView
}()override func viewDidLoad() {super.viewDidLoad()view.backgroundColor = UIColor.whiteview.addSubview(pageTitleView)view.addSubview(pageContentView)}

}

extension VCTwo: MFPageTitleViewDelegate, MFPageContentViewDelegate {
func selectedIndexInPageTitleView(pageTitleView: MFPageTitleView, selectedIndex: Int) {
self.pageContentView.setPageContentViewCurrentIndex(currentIndex: selectedIndex)
}
func pageContentViewScroll(progress: CGFloat, originalIndex: Int, targetIndex: Int) {
self.pageTitleView.setPageTitleView(progress: progress, originalIndex: originalIndex, targetIndex: targetIndex)
}
}

import UIKit

class WeiTaoVC: UIViewController,UITableViewDelegate,UITableViewDataSource {

let mArr:NSMutableArray = []
var cellHight:CGFloat = 0
var tv:UITableView?override func viewDidLoad() {super.viewDidLoad()// Do any additional setup after loading the view.NotificationCenter.default.addObserver(self, selector: #selector(test), name: NSNotification.Name(rawValue:"cellHight"), object: nil)view.backgroundColor = UIColor.whitelet path = Bundle.main.path(forResource: "daren", ofType: "json")let url = URL(fileURLWithPath: path!)do {let data = try Data(contentsOf: url)let jsonData:Any = try JSONSerialization.jsonObject(with: data, options: JSONSerialization.ReadingOptions.mutableContainers)// print(jsonData)let jsonArr:NSArray = jsonData as! NSArrayprint(jsonArr)for item in jsonArr {let k:NSDictionary = item as! NSDictionaryif k.object(forKey: "type") as! String == "0"{let md:OneMD = OneMD(headImg: k.object(forKey: "head") as! String, title: k.object(forKey: "title") as! String, detailTitle: k.object(forKey: "detailTitle") as! String, img: k.object(forKey: "img") as! String, time: k.object(forKey: "time") as! String, num: k.object(forKey: "num") as! String, type: k.object(forKey: "type") as! String)mArr.add(md)}else if k.object(forKey: "type") as! String == "1" {let md:TwoMD = TwoMD(headImg: k.object(forKey: "head") as! String, title: k.object(forKey: "title") as! String, detailTitle: k.object(forKey: "detailTitle") as! String, img: k.object(forKey: "img") as! NSMutableArray, time: k.object(forKey: "time") as! String, num: k.object(forKey: "num") as! String, type: k.object(forKey: "type") as! String)mArr.add(md)}else{let md:ThreeMD = ThreeMD(headImg: k.object(forKey: "head") as! String, title: k.object(forKey: "title") as! String, detailTitle: k.object(forKey: "detailTitle") as! String, img: k.object(forKey: "img") as! String, time: k.object(forKey: "time") as! String, num: k.object(forKey: "num") as! String, type: k.object(forKey: "type") as! String)mArr.add(md)}}} catch let error as Error? {print(error as Any)}tv = UITableView(frame:CGRect(x: 0, y: 0, width: self.view.frame.width, height: self.view.frame.height-120), style: .plain)view.addSubview(tv!)tv!.delegate = selftv!.dataSource = selftv!.register(UINib(nibName: "OneCell", bundle: Bundle.main), forCellReuseIdentifier: "cell1")tv?.register(UINib(nibName: "TwoCell", bundle: Bundle.main), forCellReuseIdentifier: "cell2")tv!.register(UINib(nibName: "ThreeCell", bundle: Bundle.main), forCellReuseIdentifier: "cell3")tv!.tableFooterView = UIView()
}func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {return mArr.count
}func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {let item = mArr[indexPath.row]if item is OneMD{let md:OneMD = mArr[indexPath.row] as! OneMDlet cell:OneCell = tableView.dequeueReusableCell(withIdentifier: "cell1") as! OneCellcell.setCellWithData(model: md)return cell} else if item is TwoMD{let md:TwoMD = mArr[indexPath.row] as! TwoMDlet cell:TwoCell = tableView.dequeueReusableCell(withIdentifier: "cell2") as! TwoCellcell.setCellWithData(model: md)print(cellHight)return cell}else{let md:ThreeMD = mArr[indexPath.row] as! ThreeMDlet cell:ThreeCell = tableView.dequeueReusableCell(withIdentifier: "cell3") as! ThreeCellcell.setCellWithData(model: md)return cell}}func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {let item = mArr[indexPath.row]if item is TwoMD{return cellHight+10} else{return 200}
}@objc func test(nofi : Notification){cellHight = nofi.userInfo!["post"] as! CGFloattv?.reloadData()/// 移除通知NotificationCenter.default.removeObserver(self)
}

}

import UIKit

class ViewController: UIViewController {

override func viewDidLoad() {super.viewDidLoad()// Do any additional setup after loading the view, typically from a nib.let path = Bundle.main.path(forResource: "daren", ofType: "json")let url = URL(fileURLWithPath: path!)do {let data = try Data(contentsOf: url)let jsonData:Any = try JSONSerialization.jsonObject(with: data, options: JSONSerialization.ReadingOptions.mutableContainers)// print(jsonData)let jsonDic:NSArray = jsonData as! NSArrayprint(jsonDic)} catch let error as Error? {print(error as Any)}}

}

swift json相关推荐

  1. iOS Swift JSON解析教程

    In this tutorial, we will learn how to parse a JSON response in our iOS Application using Swift. We ...

  2. codable swift_使用Codable进行Swift JSON解析

    codable swift In this tutorial, we'll be discussing the Codable Protocol and its forms in order to p ...

  3. Swift JSON与模型转换(HandyJSON封装)

    2018.05.02 20:20:16字数 1,493阅读 5,017 一 简介 二 特性 三 安装使用以及封装 四 使用示例 五 总结 一 简介 HandyJSON是一个用于Swift语言中的JSO ...

  4. Swift JSON 教程:使用 JSON

    原文:Swift JSON Tutorial: Working with JSON 作者:Luke Parham 译者:kmyhy 2017-1-15 更新说明:本教程由 Luke Parham 更新 ...

  5. Swift JSON转模型Xcode插件

    SwiftJSONModeler是一个Xcode插件,一键转换json字符串为Swfit模型,一键转化 YApi 平台接口为模型,并且自动引入注释. 支持struct, class 支持单json转模 ...

  6. Swift - JSON

    如果App 需要有网络功能并且有一个后端服务器处理和返回数据的话,那就基本上无法避免和JSON 打交道了.在Swift 里处理JSON 其实是一件挺棘手的事情,因为Swift 对于类型的要求非常严格, ...

  7. HandyJSON的swift json解析第三方使用教程

    文章目录 安装方法 让模型遵守协议HandyJSON,嵌套模型的子模型也要继承HandyJSON 解析json数据 从json下一个子节点进行解析 解析数组 安装方法 podfile里面 pod 'H ...

  8. iOS Swift JSON转JSONString字符串

    本人亲测有效!更多交流可以家魏鑫:lixiaowu1129,公重好:iOS过审汇总,一起探讨iOS技术! do{ let data = try? JSONEncoder().encode(jsonPr ...

  9. iOS开发之swift资料大全

    目录(?)[+] 版本:Swift github排名 https://github.com/trending,github搜索:https://github.com/search 主要工作说明:  1 ...

最新文章

  1. [Android动画] 帧动画-获取帧数( getNumberOfFrames)七
  2. 给批量用户设磁盘配额
  3. 如何让文本框中只能输入手机号码
  4. U-Mail邮件系统客户无需担心OpenSSL心脏出血漏洞
  5. 蓝桥杯 ADV-91 算法提高 素数判断
  6. 模糊逻辑学习--模糊逻辑的基础
  7. 【转载】shell中EOF的用法
  8. android设备调用usb外置摄像头方法及案例
  9. 相机靶面尺寸详解+工业相机选型
  10. 三星S8 隐藏Android功能键,三星S8获系统更新 新增虚拟按键隐藏功能
  11. Kubernetes权威指南(下)
  12. RSA密码的手动算法+快速幂算法
  13. java反转函数_在JAVA中,下列哪个函数可用于字符串的反转?
  14. jacoco—增量代码覆盖率实现
  15. Android图片加载框架最全解析(二),从源码的角度理解Glide的执行流程
  16. 弘辽科技:拼多多商品限制推广多久解封?怎么申诉?
  17. 视频教程-软考系统集成项目管理工程师视频教程(中)-软考
  18. uni-app 使用 jsencrypt
  19. 逗视 iOS客户端应用源码
  20. 使用Android Studio写一个发短信的小案例

热门文章

  1. Java 字符串数组转化为对象
  2. 小程序解析富文本编辑器中的内容
  3. HackTheBox-Beatles
  4. SpringCloud - Spring Cloud Netflix 之 Zuul网关;路由(十一)
  5. docker 1.12 版本 docker swarm 集群
  6. 【Hive】函数(UDF篇)
  7. 去掉 unigui 服务器端的 UniGUI Server 字样
  8. #C51 IIC通讯(底层配置时序)
  9. iOS 16 修改第三方库实现监听 SwiftUI 中 sheet 弹出视图的下滑关闭动作
  10. mysql 中set函数的用法