Ben*_*mas 5 twitter ios twitter-oauth swift xcode6
我认为Twitter Kit应该可以帮助开发人员在几行代码中集成Twitter.至少可以说在线文档很差.我只是想在一个表视图控制器中在我的应用程序中显示单个用户的时间轴.我想要只读,访客只能访问时间表.下面的在线文档中的复制/粘贴只会显示2个单元格,其中填充了灰色图像和Twitter徽标,但没有推文.怎么了?谢谢
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's 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))
}
}
Run Code Online (Sandbox Code Playgroud)
您需要致电:cell.configureWithTweet(tweet)
在tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath)
| 归档时间: |
|
| 查看次数: |
2941 次 |
| 最近记录: |