Skip to content

Commit

Permalink
第七天-tableView刷新
Browse files Browse the repository at this point in the history
1.用了下GCD的延迟
  • Loading branch information
qianyb committed Dec 22, 2018
1 parent 6250030 commit b42117f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
TargetAttributes = {
9F7B45B31C46A47700258538 = {
CreatedOnToolsVersion = 7.2;
DevelopmentTeam = F3YT8BWBYJ;
LastSwiftMigration = 0830;
};
};
Expand Down Expand Up @@ -265,6 +266,7 @@
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
DEVELOPMENT_TEAM = F3YT8BWBYJ;
INFOPLIST_FILE = PullToRefresh/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = me.appkitchen.PullToRefresh;
Expand All @@ -277,6 +279,7 @@
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
DEVELOPMENT_TEAM = F3YT8BWBYJ;
INFOPLIST_FILE = PullToRefresh/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = me.appkitchen.PullToRefresh;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
18 changes: 11 additions & 7 deletions Project 07 - PullToRefresh/PullToRefresh/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,29 @@ import UIKit

class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {

var index = 0
let cellIdentifer = "NewCellIdentifier"

let favoriteEmoji = ["🤗🤗🤗🤗🤗", "😅😅😅😅😅", "😆😆😆😆😆"]
let newFavoriteEmoji = ["🏃🏃🏃🏃🏃", "💩💩💩💩💩", "👸👸👸👸👸", "🤗🤗🤗🤗🤗", "😅😅😅😅😅", "😆😆😆😆😆" ]
var emojiData = [String]()
var tableViewController = UITableViewController(style: .plain)
var tableView: UITableView!

var refreshControl = UIRefreshControl()
var navBar: UINavigationBar = UINavigationBar(frame: CGRect(x: 0, y: 0, width: 375, height: 64))

override func viewDidLoad() {
super.viewDidLoad()
tableView = UITableView(frame: self.view.bounds, style: .plain)

emojiData = favoriteEmoji
let emojiTableView = tableViewController.tableView
let emojiTableView = tableView

emojiTableView?.backgroundColor = UIColor(red:0.092, green:0.096, blue:0.116, alpha:1)
emojiTableView?.dataSource = self
emojiTableView?.register(UITableViewCell.self, forCellReuseIdentifier: cellIdentifer)

tableViewController.refreshControl = self.refreshControl
tableView.refreshControl = self.refreshControl
self.refreshControl.addTarget(self, action: #selector(ViewController.didRoadEmoji), for: .valueChanged)

self.refreshControl.backgroundColor = UIColor(red:0.113, green:0.113, blue:0.145, alpha:1)
Expand Down Expand Up @@ -64,7 +66,6 @@ class ViewController: UIViewController, UITableViewDataSource, UITableViewDelega

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: cellIdentifer)! as UITableViewCell

cell.textLabel!.text = self.emojiData[indexPath.row]
cell.textLabel!.textAlignment = NSTextAlignment.center
cell.textLabel!.font = UIFont.systemFont(ofSize: 50)
Expand All @@ -78,9 +79,12 @@ class ViewController: UIViewController, UITableViewDataSource, UITableViewDelega
//RoadEmoji

func didRoadEmoji() {
self.emojiData = newFavoriteEmoji
self.tableViewController.tableView.reloadData()
self.refreshControl.endRefreshing()
DispatchQueue.main.asyncAfter(deadline:DispatchTime.now() + 3 ) {
self.emojiData = [self.newFavoriteEmoji,self.favoriteEmoji][self.index]
self.tableView.reloadData()
self.refreshControl.endRefreshing()
self.index = (self.index + 1) % 2
}
}

override var preferredStatusBarStyle : UIStatusBarStyle {
Expand Down

0 comments on commit b42117f

Please sign in to comment.