Add non jomlo sample
Seto Elkahfi committed
Apr 20, 2017 at 18:02 UTC
42b5fbecfacb51614e264c13e599bea2ccd2c378
2 files changed
+128
-13
Example/JomloTableView/Base.lproj/Main.storyboard
+9
-1
@@ -58,12 +58,19 @@
58
<scene sceneID="3Te-CE-0jz">
59
<objects>
60
<viewController id="NyT-1O-xwC" customClass="NotJomloSimpleTableViewController" customModule="JomloTableView_Example" customModuleProvider="target" sceneMemberID="viewController">
61
- <tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="44" sectionHeaderHeight="28" sectionFooterHeight="28" id="bTg-b3-lO0">
61
+ <tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="88" sectionHeaderHeight="28" sectionFooterHeight="28" id="bTg-b3-lO0">
62
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
63
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
64
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
65
+ <connections>
66
+ <outlet property="dataSource" destination="NyT-1O-xwC" id="3Lx-j8-Qfd"/>
67
+ <outlet property="delegate" destination="NyT-1O-xwC" id="w4e-WI-NSR"/>
68
+ </connections>
69
</tableView>
70
<navigationItem key="navigationItem" id="Lmi-4X-6VJ"/>
71
+ <connections>
72
+ <outlet property="tableView" destination="bTg-b3-lO0" id="dSf-yq-J7f"/>
73
+ </connections>
74
</viewController>
75
<placeholder placeholderIdentifier="IBFirstResponder" id="q1O-6s-vbD" userLabel="First Responder" sceneMemberID="firstResponder"/>
76
</objects>
@@ -188,6 +195,7 @@
195
<tabBarController title="SimpleTableView" automaticallyAdjustsScrollViewInsets="NO" id="u5j-Mu-QBn" sceneMemberID="viewController">
196
<toolbarItems/>
197
<tabBar key="tabBar" contentMode="scaleToFill" id="Rq8-R7-bbG">
198
+ <rect key="frame" x="0.0" y="0.0" width="1000" height="1000"/>
199
<autoresizingMask key="autoresizingMask"/>
200
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
201
</tabBar>
Example/JomloTableView/View Controllers/NotJomloSimpleTableViewController.swift
+119
-12
@@ -7,29 +7,136 @@
7
//
8
9
import UIKit
10
+import TwitterKit
11
12
class NotJomloSimpleTableViewController: UIViewController {
13
14
+ @IBOutlet var tableView: UITableView!
15
+
16
+ var tweets = [Tweet]()
17
+
18
+ let client = TWTRAPIClient()
19
+ var loginButton: TWTRLogInButton!
20
+
21
override func viewDidLoad() {
22
super.viewDidLoad()
23
+ tableView.isHidden = true
24
+
25
+ loginButton = TWTRLogInButton { (session, error) in
26
+ if let session = session {
27
+ print("Signed as: \(session.userName)")
28
+ self.loadTweets()
29
+ } else {
30
+ print("Error: \(error?.localizedDescription)")
31
+ }
32
+ }
33
+ loginButton.center = view.center
34
+ view.addSubview(loginButton)
35
16
- // Do any additional setup after loading the view.
36
}
18
-
19
- override func didReceiveMemoryWarning() {
20
- super.didReceiveMemoryWarning()
21
- // Dispose of any resources that can be recreated.
37
+
38
+ internal func loadTweets() {
39
+
40
+ let searchEndPoint = "https://api.twitter.com/1.1/search/tweets.json"
41
+ let params = ["q" : "jomlo"]
42
+ var clientError: NSError?
43
+
44
+ let request = client.urlRequest(withMethod: "GET", url: searchEndPoint, parameters: params, error: &clientError)
45
+
46
+ client.sendTwitterRequest(request) { (response, data, connectionError) in
47
+
48
+ if let data = data {
49
+ self.populate(data: data)
50
+ }
51
+
52
+ if let error = connectionError {
53
+ print("Error: \(error.localizedDescription)")
54
+ }
55
+
56
+
57
+ }
58
}
59
60
+ internal func populate(data: Data) {
61
+ do {
62
+ if let json = try JSONSerialization.jsonObject(with: data, options: []) as? [String: Any] {
63
+ // print("json: \(json)")
64
+ if let statuses = json["statuses"] as? [Any] {
65
+ // print("statuses: \(statuses)")
66
+ for status in statuses {
67
+ print("status: \(status)")
68
+ let status = status as! [String: Any]
69
+ // print("\(status["text"])")
70
+ let user = status["user"] as! [String: Any]
71
+
72
+ let tweet = Tweet(screenName: user["screen_name"] as! String, name: user["name"] as! String, text: status["text"] as! String)
73
+ // profile_image_url_https
74
+ tweets.append(tweet)
75
+
76
+ }
77
+ DispatchQueue.main.async {
78
+ tableView.isHidden = false
79
+ self.loginButton.removeFromSuperview()
80
+ self.tableView.reloadData()
81
+ }
82
+ }
83
+ }
84
+
85
+
86
+ } catch let jsonError as NSError {
87
+ print("json error: \(jsonError.localizedDescription)")
88
+ }
89
+ }
90
25
- /*
26
- // MARK: - Navigation
91
+}
92
+
93
+extension NotJomloSimpleTableViewController: UITableViewDelegate {
94
+
95
+ func numberOfSections(in tableView: UITableView) -> Int {
96
+ return 1
97
+ }
98
+
99
+ func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
100
+ return 88
101
+ }
102
+
103
+ func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat {
104
+ return 88
105
+ }
106
+}
107
28
- // In a storyboard-based application, you will often want to do a little preparation before navigation
29
- override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
30
- // Get the new view controller using segue.destinationViewController.
31
- // Pass the selected object to the new view controller.
108
+extension NotJomloSimpleTableViewController: UITableViewDataSource {
109
+
110
+ func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
111
+ return tweets.count
112
}
33
- */
113
+
114
+ func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
115
+
116
+ var cell = tableView.dequeueReusableCell(withIdentifier: "SimpleCell") as? SimpleCell
117
+
118
+ if cell == nil {
119
+ let nib = UINib(nibName: "SimpleCell", bundle: nil)
120
+ tableView.register(nib, forCellReuseIdentifier: "SimpleCell")
121
+ cell = tableView.dequeueReusableCell(withIdentifier: "SimpleCell") as? SimpleCell
122
+ }
123
+
124
+ cell?.textLabel?.text = "@\(tweets[indexPath.row].screenName!) \(tweets[indexPath.row].name!)"
125
+ cell?.subTitleLabel.text = tweets[indexPath.row].text!
126
+
127
+ return cell!
128
+ }
129
+
130
+}
131
132
+class Tweet {
133
+ var screenName: String!
134
+ var name: String!
135
+ var text: String!
136
+
137
+ init(screenName: String, name: String, text: String) {
138
+ self.screenName = screenName
139
+ self.name = name
140
+ self.text = text
141
+ }
142
}