Created
August 6, 2016 05:37
-
-
Save niwatako/8fd17e783800ceff6a2090b3f371fb93 to your computer and use it in GitHub Desktop.
UITableViewControllerにUITableViewDataSourceになるための実装を追加 #CodePiece #realm_swift #realm_jp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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