1

以下のコードは、配列 'tweets' にツイート ID が表示されたテーブル ビューを正常に表示します。これを変更して、特定のユーザー ハンドルまたはハッシュタグのすべてのツイートを表示する方法を教えてください。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))
}
4

1 に答える 1