Skip to content

Instantly share code, notes, and snippets.

@hayate1996
Last active August 29, 2015 14:27
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save hayate1996/475e7147c9dfc08e0ac4 to your computer and use it in GitHub Desktop.
import UIKit
class TimelineViewController: UITableViewController, UITableViewDelegate, UITableViewDataSource {
let cellIdentifier = "tweetCell"
var tweets:[Dictionary<String, AnyObject>]?
override func viewDidLoad() {
super.viewDidLoad()
// Uncomment the following line to preserve selection between presentations
// self.clearsSelectionOnViewWillAppear = false
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem()
self.navigationItem.title = "Timeline"
tweets = [ ["name": "Hiro", "description": "Hey! Going to be in Frisco in October. Was hoping to have a meeting to talk about @thinkwall if you're around?", "icon":"twitter_icon"],
["name": "Jeff", "description": "Got the shirt @jasoncosta thanks man! Loving the #twitter bird on the shirt :-)", "icon":"user_b_icon"],
["name": "Chris", "description": "Loving the #twitter bird on the shirt :-)", "icon":"user_c_icon"],
["name": "Jeff", "description": "Was hoping to have a meeting to talk about @thinkwall if you're around?, CCC?", "icon":"user_b_icon"],
["name": "Chris", "description": "My old is 17.", "icon":"user_c_icon"],
["name": "Hiro", "description": "My name is Hiro", "icon":"user_c_icon"],
["name": "Jeff", "description": "Got the shirt @jasoncosta thanks man!", "icon":"user_b_icon"],
["name": "Chris", "description": "Loving the #twitter bird on the shirt :-)", "icon":"user_c_icon"],
["name": "Jeff", "description": "How old are you, CCC?", "icon":"user_b_icon"],
["name": "Chris", "description": "Loving the #twitter bird on the shirt :-)", "icon":"user_c_icon"],
["name": "Hiro", "description": "Was hoping to have a meeting to talk about", "icon":"user_c_icon"],
["name": "Jeff", "description": "Got the shirt @jasoncosta thanks man!", "icon":"user_b_icon"],
["name": "Chris", "description": "Loving the #twitter bird on the shirt", "icon":"user_c_icon"]]
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
// MARK: - Table view data source
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
// #warning Potentially incomplete method implementation.
// Return the number of sections.
return 1
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// #warning Incomplete method implementation.
// Return the number of rows in the section.
if let tweetsList = tweets {
return tweetsList.count
}
return 0
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var aCell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier, forIndexPath: indexPath) as? UITableViewCell
// Configure the cell...
if aCell == nil {
aCell = UITableViewCell(style: .Subtitle, reuseIdentifier: cellIdentifier)
}
var cell = aCell!
cell.imageView?.image = UIImage(named: (tweets![indexPath.row]["icon"] as? String)!)
cell.textLabel?.text = tweets![indexPath.row]["description"] as? String
cell.detailTextLabel?.text = tweets![indexPath.row]["name"] as? String
return cell
}
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
self.performSegueWithIdentifier("showTweetDetailViewController", sender: nil)
}
override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return 50.0
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment