Skip to content

Instantly share code, notes, and snippets.

@niwatako
Created August 6, 2016 05:37
Show Gist options
  • Select an option

  • Save niwatako/8fd17e783800ceff6a2090b3f371fb93 to your computer and use it in GitHub Desktop.

Select an option

Save niwatako/8fd17e783800ceff6a2090b3f371fb93 to your computer and use it in GitHub Desktop.
UITableViewControllerにUITableViewDataSourceになるための実装を追加 #CodePiece #realm_swift #realm_jp
class TimelineViewController: UITableViewController {
// 中略
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return timeline?.count ?? 0
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("timelineCell", forIndexPath: indexPath) as! TimelineCell
let tweet = timeline![indexPath.row]
cell.nameLabel.text = tweet.name
cell.tweetTextView.text = tweet.text
NSURLSession.sharedSession().dataTaskWithRequest(NSURLRequest(URL: NSURL(string: tweet.iconURL)!)) { (data, response, error) -> Void in
if let _ = error {
return
}
dispatch_async(dispatch_get_main_queue()) {
let image = UIImage(data: data!)!
cell.iconView.image = image
}
}.resume()
return cell
}
override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return UITableViewAutomaticDimension
}
// 中略
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment