Swift:我的第三个Demo

这里Demo工作量是我目前做的做大的,相应的知识点有

1 页面UI布局

2 delegate委托模式的实现

3 Alamofire网络请求

4 JSON初体验

5 自定义TableViewCell

6 NavigationViewController初体验

7 Kingfisher加载图片的使用

8 TableView的界面自定义,如何刷新界面

 

代码如下

文件名:Appdelegate.swift

//
//  AppDelegate.swift
//  RxSwiftTest
//
//  Created by travey on 2018/11/5.
//  Copyright © 2018年 ZhouShijie. All rights reserved.
//

import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow? // 系统自带的window视图,需要给他配置根视图

    // 这个函数是程序的入口
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        // Override point for customization after application launch.
        window = UIWindow(frame: UIScreen.main.bounds) // 创建一个window的实例
        let navigationViewController = UINavigationController.init(rootViewController: ViewController()) // 创建一个UINavigationController的实例,并且初始化他的根视图是ViewController类型的一个实例,UINavigationController是UIViewcontroller的子类
        window?.backgroundColor = .white // 设置window的背景颜色为白色
        window?.rootViewController = navigationViewController // 设置window的根视图为刚才定义的navigationViewController
        window?.makeKeyAndVisible() // 这句话必须加
        return 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:.
    }


}

文件名: ViewController.swift


//  ViewController.swift
//  RxSwiftTest
//
//  Created by travey on 2018/11/5.
//  Copyright © 2018年 ZhouShijie. All rights reserved.


import UIKit
import RxSwift
import RxCocoa
import SnapKit
import RxDataSources
import Kingfisher
import SwiftyJSON
import Alamofire

// 定义一个图书的类,这个是数据源的数据结构类型,三个变量都是字符串
class Book: NSObject {
    var title = "" // 主标题
    var subtitle = "" // 副标题
    var image = "" // 图片的URL字符串
}

class ViewController: UIViewController {
    
    // 定义各种空间
    var addbtn: UIBarButtonItem! // 添加按钮,这里没有实现相应的相应
    var refreshbtn: UIBarButtonItem! // 刷新按钮
    var tableView: UITableView! // 表单
    var canEditbtn: UIBarButtonItem! // 表单是否能编辑按钮
    var originalNumberOfImage: Int! // 显示图书的原本个数

    let URLString = "https://api.douban.com/v2/book/search" // 网络请求的URL
  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值