- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
问题
将返回的 Twitter JSON 提要加载到 TwitterKit TableView 单元格时,不会加载个人资料图像和媒体图像。所有其他数据(用户名、转推状态、描述、链接)加载并正确显示在 twitterTableView 中,但图像没有。
JSON 提要包含准确的图像 URL。
有没有人遇到过这种情况,或者有允许在 View Controller 中嵌套 Twitter 表的解决方案?
版本信息
Xcode v7.0.1
代码库:Swift 2.0
应用兼容性 iOS 8.3+
推特核心v1.12.0
TwitterKit v1.12.0
Storyboard中的 ViewController
元数据工作流程
ViewController中的相关代码
import UIKit
import Alamofire
import SwiftyJSON
import RealmSwift
import TwitterKit
class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate, UICollectionViewDataSource, UICollectionViewDelegate, TWTRTweetViewDelegate {
@IBOutlet weak var socialView: UIView!
@IBOutlet weak var friendCollectionView: UICollectionView!
@IBOutlet weak var twitterTableView: UITableView!
@IBOutlet weak var friendColletionViewHeightConstraint: NSLayoutConstraint!
@IBOutlet weak var twitterTableViewHeightConstraint: NSLayoutConstraint!
var tweets: [TWTRTweet] = [] {
didSet {
twitterTableView.reloadData()
}
}
var tweetHeights:[Int:CGFloat] = [:]
var isLoadingTweets = false
let tweetTableCellReuseIdentifier = "TweetCell"
var prototypeCell: TWTRTweetTableViewCell?
var isLoadingFriend = false
var friends:[Friend] = [] {
didSet {
friendCollectionView.reloadData()
}
}
override func viewDidLoad() {
super.viewDidLoad()
self.loadInfo()
self.loadFriends()
self.loadTweets()
// Create a single prototype cell for height calculations.
self.prototypeCell = TWTRTweetTableViewCell(style: .Default, reuseIdentifier: tweetTableCellReuseIdentifier)
// Register the identifier for TWTRTweetTableViewCell.
self.twitterTableView.registerClass(TWTRTweetTableViewCell.self, forCellReuseIdentifier: tweetTableCellReuseIdentifier)
}
func loadInfo(){
print("loads basic info")
// code removed to simplify post
}
func loadFriends(){
print("loads friendsCollectionView inside Info")
// code removed to simplify post
}
func loadTweets(){
print("loadTweets")
// Do not trigger another request if one is already in progress.
if self.isLoadingTweets {
return
}
self.isLoadingTweets = true
Alamofire.request(APIService.Router.TwitterSearch(searchType: "hashtag", searchTerm: "something", userSocialProfileID: ""))
.responseString { response in
print("request: \(response.0!)")
print("\n*******loadTweets********\n\n\(response.2.value!)\n\n**************\n")
}
.responseJSON { response in
// print("\n*******loadTweets:JSON********\n\n\(response.2.value!)\n\n**************\n")
if let json = response.2.value {
var jsonObj = JSON(json)
if let results = jsonObj["results"].dictionary{
if let jsonTweets = results["statuses"]!.arrayObject {
// print("The tweets are \n\(jsonTweets)")
self.tweets = TWTRTweet.tweetsWithJSONArray(jsonTweets) as! [TWTRTweet]
} else {
print("jsonTweets are not an array of Objects")
}
} else {
print("Results is not a dictionary.")
}
dispatch_async(dispatch_get_main_queue(),{
self.twitterTableViewHeightConstraint.constant = 0
for (_, tweetHeight) in self.tweetHeights {
self.twitterTableViewHeightConstraint.constant += tweetHeight
}
self.isLoadingTweets = false
})
} else {
print("value was not json...or something is wrong with the code")
}
}
}
//MARK: UITABLEVIEW
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return tweets.count
}
func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
let tweet = self.tweets[indexPath.row] as TWTRTweet!
if tweets.count > indexPath.row {
prototypeCell?.configureWithTweet(tweet)
}
let tweetHeight = TWTRTweetTableViewCell.heightForTweet(tweet, width: tableView.bounds.width)
self.tweetHeights[indexPath.row] = tweetHeight
return tweetHeight
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier(tweetTableCellReuseIdentifier, forIndexPath: indexPath) as! TWTRTweetTableViewCell
// Assign the delegate to control events on Tweets.
cell.tweetView.delegate = self
cell.tweetView.showActionButtons = false
cell.tweetView.linkTextColor = UIColor().cosMediumPurple()
// Retrieve the Tweet model from loaded Tweets.
let tweet = tweets[indexPath.row] as TWTRTweet!
// Configure the cell with the Tweet.
cell.configureWithTweet(tweet)
// Return the Tweet cell.
return cell
}
}
最佳答案
答案其实很烦人也很简单。 TWTRTweet 类不包含个人资料图像或附加媒体的变量。推特提供方法:
TWTRTweet.tweetsWithJSONArray()
但是该方法会立即丢弃您需要的图像的任何 URL。您需要构建自定义解析方法。我已经完成了一些 Twitter JSON 解析工作,您可以查看 here.
关于ios - Swift 的 TwitterKit 不显示图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33423621/
我已经为我的 Cordova 项目实现了 Fabric 和 Twitter Kit 来实现 Twitter 登录。在 Android Studio 中完美运行。将 Fabric 和 Twitter 套
我正在使用 TwitterKit 和 Firebase 来允许用户使用 Twitter 登录。我第一次尝试使用 Twitter 登录时失败并显示错误: [TwitterCore] Cannot ver
我安装了这些 pod 文件。 pod 'TwitterKit' pod 'TwitterCore' 当我尝试导入文件 i. e #import 它显示未找到错误。 为什么要提出任何想法?有什么问题或有
我通过 Fabric TwitterKit 在我的应用中显示 Twitter 时间线。 我想通过仅显示@特定用户的推文来过滤时间线。我已阅读 here 中的文档关于如何在时间轴中过滤推文。对我来说不幸
我使用TwitterKit发送推文,使用此代码。 TWTRComposer *twitterComposer = [[TWTRComposer alloc] init]; [twitterCompos
我试图使用 TwitterKit 和 Fabric 框架来获取用户时间线,当我运行以下代码时,我得到的是这个输出而不是时间线 output let client = TWTRAPIClient
我正在使用 TwitterKit for Android在我的应用程序中显示推文。效果很好,但由于某种原因,它没有在每条推文下方显示转推和点赞的数量。 这是我的代码: SearchTimeline s
我有一个请愿 url 请求,但问题是响应数据为 nil ,对于其他 url 请求,请愿成功但没有这个功能!任何想法 ? let client = TWTRAPIClient() let sta
将照片从我的应用程序上传到用户的 Twitter 帐户工作正常,但突然间出现此错误: Error Domain=TwitterAPIErrorDomain Code=32 "Request faile
我想向 TwitterKit iOS SDK 注入(inject)或伪造登录。我正在尝试为我的库(这是最重要的 Twitter API 的一种包装器)编写一些单元测试。 不幸的是,Fabric 要求用
我们是否可以手动登录用户并创建一个 TWTRSession 以便继续与 TwitterKit 一起使用?我已经尝试过: NSDictionary *twSessionInfo = [self.acco
有人可以解释一下如何使用 TwitterKit 开始完成设置和 iOS/Swift View Controller 来显示单个用户的时间轴。 Fabric 上的文档很差,没有解释所有必要的应用程序委托
我正在使用 this API获取用户的关注者列表,并按照文档中的描述返回 JSON 格式的关注者。这是返回对象的片段: { "users": [ { "id": 2960784
我已经实现了 TwitterKit 推文时间轴,并且对于某些推文,个人资料图片非常大并且忘记了它的长宽比。 是否有修复此问题的黑客?我试过通过子类,但最终一无所获。覆盖文本大小也是如此(因为它不是一个
我正在检索并在表格 View 中显示推文列表。以下代码从搜索中获取一堆推文并显示它们。这很好用! Twitter.sharedInstance().logInGuestWithCompletion
我正在尝试使用开发人员门户中提供的说明登录 twitterkit,但无济于事。每次我尝试这样做时,无论是使用 loginWithCompletion、loginWithViewController 还
我在通过 Fabric 使用 TwitterKit 时看到了一个相当神秘的崩溃。 我的应用程序在这一行崩溃: Fabric.with([Crashlytics.self, Twitter.self])
我已采取以下措施来解决此问题 在build设置下,将"is"设置为“允许在 FrameworkModules 中包含非模块化内容” 已清理的项目 通过删除下面的数据来真正清理项目〜/Library/D
我制作了自己的 UITableViewController,并尝试让我的 TWTRTweetTableViewCell 对象来检测链接。我有一个 TWTRTweet 对象数组,用于生成 TableVi
我正在尝试从我的应用程序向 Twitter 发布一些内容,不幸的是,由于 iOs 11,旧方法不再适用,所以我正在实现 twitterKit 并发现一些尖峰。 当我没有安装该应用程序时,它会运行下面的
我是一名优秀的程序员,十分优秀!