【问题标题】:Loading array of user tweets for embedded user tweet timeline为嵌入式用户推文时间线加载用户推文数组
【发布时间】:2015-03-17 08:27:43
【问题描述】:

以下代码成功显示了一个表格视图,其中显示了数组“tweets”中的推文 ID。有人可以告诉我如何修改它以显示特定用户句柄或 hastag 的所有推文吗?我想我必须使用 TwitterKit 中的 loadUserWithID 方法,但不知道如何实现它。非常感谢

import UIKit
import TwitterKit

class TwitterViewController: UITableViewController, TWTRTweetViewDelegate {


let tweetTableReuseIdentifier = "TweetCell"
// Hold all the loaded Tweets
var tweets: [TWTRTweet] = [] {
    didSet {
        tableView.reloadData()
    }
}
let tweetIDs = [
    "184701590"] // our favorite bike Tweet

override func viewDidLoad() {


    Twitter.sharedInstance().logInGuestWithCompletion { guestSession, error in
        if (guestSession != nil) {
            Twitter.sharedInstance().APIClient.loadTweetsWithIDs(self.tweetIDs) { tweets, error in
                if let ts = tweets as? [TWTRTweet] {
                    self.tweets = ts
                } else {
                    println("Failed to load tweets: \(error.localizedDescription)")
                }
            }
        }
    }
    // 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)

            }

// 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
    cell.configureWithTweet(tweet)
    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))
}

【问题讨论】:

    标签: ios swift twitter twitter-fabric


    【解决方案1】:

    TwitterKit 支持直接显示用户时间线

    class UserTimelineViewController: TWTRTimelineViewController, TWTRTweetViewDelegate {
    
      convenience init() {
        let dataSource = TWTRUserTimelineDataSource(screenName: "TomCruise", APIClient: TWTRAPIClient())
        self.init(dataSource: dataSource)
    
        self.title = "@\(dataSource.screenName)"
      }
    
      func tweetView(tweetView: TWTRTweetView, didSelectTweet tweet: TWTRTweet) {
        print("Selected tweet with ID: \(tweet.tweetID)")
      }
    
    }
    

    您可以在此处查看更多详细信息:https://dev.twitter.com/twitter-kit/ios/show-timelines

    【讨论】:

      猜你喜欢
      • 2013-07-05
      • 1970-01-01
      • 1970-01-01
      • 2015-08-16
      • 2016-07-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-29
      相关资源
      最近更新 更多