Twitter - iOS

I thought the Twitter Kit should help developers integrate Twitter into multiple lines of code. At the very least, online documentation is poor. I'm just trying to display a single user timeline in my application in a table view controller. I want only reading, only guest access to the timeline. The copy / paste from the online documentation below simply shows two cells filled with a gray image and twitter logo, but without tweets. What's wrong? Thanks

import UIKit import TwitterKit class TwitterViewController: UITableViewController, TWTRTweetViewDelegate { let tweetTableReuseIdentifier = "TweetCell" // Hold all the loaded Tweets var tweets: [TWTRTweet] = [] { didSet { tableView.reloadData() } } let tweetIDs = ["20", // @jack first Tweet "510908133917487104"] // our favorite bike Tweet override func viewDidLoad() { // Setup the table view tableView.estimatedRowHeight = 150 tableView.rowHeight = UITableViewAutomaticDimension // Explicitly set on iOS 8 if using automatic row height calculation tableView.allowsSelection = false tableView.registerClass(TWTRTweetTableViewCell.self, forCellReuseIdentifier: tweetTableReuseIdentifier) Twitter.sharedInstance().logInGuestWithCompletion { guestSession, error in if (guestSession != nil) { // make API calls that do not require user auth } else { println("error: \(error.localizedDescription)"); } } // Load Tweets Twitter.sharedInstance().APIClient.loadTweetsWithIDs(tweetIDs) { tweets, error in if let ts = tweets as? [TWTRTweet] { self.tweets = ts } else { println("Failed to load tweets: \(error.localizedDescription)") } } } // MARK: UITableViewDelegate Methods override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return self.tweets.count } override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { let tweet = tweets[indexPath.row] let cell = tableView.dequeueReusableCellWithIdentifier(tweetTableReuseIdentifier, forIndexPath: indexPath) as TWTRTweetTableViewCell cell.tweetView.delegate = self return cell } override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat { let tweet = tweets[indexPath.row] return TWTRTweetTableViewCell.heightForTweet(tweet, width: CGRectGetWidth(self.view.bounds)) } } 
+5
source share
2 answers

You need to call: cell.configureWithTweet(tweet)

in tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath)

+2
source

Stephen is here, one of the developers of the Twitter Kit.

The best way to do this now is to subclass TWTRTimelineViewController and set the dataSource property.

 class UserTimelineViewController: TWTRTimelineViewController, TWTRTweetViewDelegate { convenience init() { // Show a timeline of @jack Tweets let dataSource = TWTRUserTimelineDataSource(screenName: "jack", APIClient: TWTRAPIClient()) self.init(dataSource: dataSource) // Set the title for Nav bar self.title = "@\(dataSource.screenName)" } func tweetView(tweetView: TWTRTweetView, didSelectTweet tweet: TWTRTweet) { // Log a message whenever a user taps on a tweet print("Selected tweet with ID: \(tweet.tweetID)") } } 

Custom Timeline Screenshot

+2
source

Source: https://habr.com/ru/post/1214861/


All Articles