- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我使用一个教程将我的 Twitter 主页包含在我的代码中,但对我来说不起作用。
这是代码
@implementation VSViewController
- (void)viewDidLoad
{
[super viewDidLoad];
[self twitterTimeline];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)twitterTimeline {
ACAccountStore *account = [[ACAccountStore alloc] init]; // Creates AccountStore object.
// Asks for the Twitter accounts configured on the device.
ACAccountType *accountType = [account accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
[account requestAccessToAccountsWithType:accountType options:nil completion:^(BOOL granted, NSError *error)
{
// If we have access to the Twitter accounts configured on the device we will contact the Twitter API.
if (granted == YES){
NSArray *arrayOfAccounts = [account accountsWithAccountType:accountType]; // Retrieves an array of Twitter accounts configured on the device.
// If there is a leat one account we will contact the Twitter API.
if ([arrayOfAccounts count] > 0) {
ACAccount *twitterAccount = [arrayOfAccounts lastObject]; // Sets the last account on the device to the twitterAccount variable.
NSURL *requestAPI = [NSURL URLWithString:@"http://api.twitter.com/1.1/statuses/user_timeline.json"]; // API call that returns entires in a user's timeline.
// The requestAPI requires us to tell it how much data to return so we use a NSDictionary to set the 'count'.
NSMutableDictionary *parameters = [[NSMutableDictionary alloc] init];
[parameters setObject:@"100" forKey:@"count"];
[parameters setObject:@"1" forKey:@"include_entities"];
// This is where we are getting the data using SLRequest.
SLRequest *posts = [SLRequest requestForServiceType:SLServiceTypeTwitter requestMethod:SLRequestMethodGET URL:requestAPI parameters:parameters];
posts.account = twitterAccount;
// The postRequest: method call now accesses the NSData object returned.
[posts performRequestWithHandler:
^(NSData *response, NSHTTPURLResponse
*urlResponse, NSError *error)
{
// The NSJSONSerialization class is then used to parse the data returned and assign it to our array.
self.array = [NSJSONSerialization JSONObjectWithData:response options:NSJSONReadingMutableLeaves error:&error];
if (self.array.count != 0) {
dispatch_async(dispatch_get_main_queue(), ^{
[self.tableView reloadData]; // Here we tell the table view to reload the data it just recieved.
});
}
}];
}
} else {
// Handle failure to get account access
NSLog(@"%@", [error localizedDescription]);
}
}];
}
#pragma mark Table View Data Source Mehtods
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
// Returns the number of rows for the table view using the array instance variable.
return [_array count];
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
// Creates each cell for the table view.
static NSString *cellID = @"CELLID" ;
UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:cellID];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
}
// Creates an NSDictionary that holds the user's posts and then loads the data into each cell of the table view.
它在这里崩溃并出现错误 -[__NSCFDictionary objectAtIndexedSubscript:]: 无法识别的选择器发送到实例
NSDictionary *tweet = _array[indexPath.row];
cell.textLabel.text = tweet[@"text"];
return cell;
}
最佳答案
问题是 _array
不是数组(它是字典)。
您只需阅读错误消息即可看到这一点。
您不能对 JSONObjectWithData:options:error:
会给您什么样的对象做出任何假设;这取决于 JSON 数据的外观。在这种情况下,JSON 结构导致 Objective-C 等效项成为 NSDictionary。事实上,您可能已经调用您的 array
实例变量 NSArray 没有区别;在 Objective-C 中,对象就是它的本来面目(多态性)。
你没有早点发现问题,因为 count
是 NSDictionary 和 NSArray 的方法,所以当你说 self.array.count
时你没有崩溃>.
关于ios - -[__NSCFDictionary objectAtIndexedSubscript :]: unrecognized selector sent to instance,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23846281/
我可以同步我的 Gmail 收件箱,但发送的文件夹不起作用。 这是我的 .mbsyncrc IMAPStore martinstabenfeldt-remote Account martins
我正在尝试从 nodeJS 发送电子邮件(使用 nodemailer 库),目前我在整个邮寄过程中遇到了一些超时问题。那不是我需要帮助的问题。我确实需要帮助的问题是,当它到达日志记录部分时,成功将为空
我在 WordPress 模板中使用 Contact Form 7 插件。我创建了表单和相关的 CSS,所以一切正常。当我单击发送按钮并成功发送电子邮件时,我需要执行以下操作。表单应该消失并显示“已发
我正在从辅助角色向服务总线队列发送消息。我注意到一些消息会随机丢失。 当我调试时,我在 Send 方法之后设置了一个断点,并登录到我的 Azure 面板以检查消息队列是否增加。我发现奇怪的是,有时消息
我是网站安全的新手,目前正在尝试深入了解同源策略。虽然在 stackoverflow 和其他地方有关于 SOP 概念的非常好的帖子,但我找不到关于 chrome 和其他浏览器是否允许跨域 XHR po
我正在从官方文档中学习 Solidity,并在我创建简单硬币的练习中进行堆栈: pragma solidity ^0.4.20; // should actually be 0.4.21 con
我们有一个需求,其中服务器需要将数据推送到各个客户端。所以我们继续使用 SSE(服务器发送事件)。我浏览了文档,但仍然不清楚这个概念。我有以下疑问: 场景 1。假设有 10 个客户。所以所有 10 个
我对 javascript/jquery 缺乏经验。我正在阅读 http://api.jquery.com/mouseover/ 的文档其中指出: The mouseover event is sen
所以我理解服务器发送事件的概念( EventSource ): 客户端通过 EventSource 连接到端点 客户端只监听从端点发送的消息 我感到困惑的是它在服务器上的工作方式。我看过不同的例子,但
我看过 here和 there尝试弄清楚服务器发送的事件是在传输级别。我还不确定。 两个消息来源都声称它们“只是 http”。然而,至少有两种方式可以解释这样的陈述。 当我第一次阅读那些文章时,我假设
我正在尝试使用 PHPMailer 在我的网站上创建联系表单。我在设置时遇到一些问题。我正在尝试使用 G-mail 作为我的 smtp 主机。我想知道是否有人可以帮助解决这个问题? 这是我的邮件代码:
我有一个大约 150 封电子邮件的文件夹,全部保存为 HTML 文件(Firefox 扩展),并且我需要捕获始终在“已发送”行中找到的年份;如下图所示。 我尝试使用 RegEx 但失败了;它根本不会打
我正在 Swift 中基于 NSObject 开发自定义类。它是一个状态菜单图标/菜单助手。当我收到在自定义类中单击图标的事件时,我想以 NSButton 允许创建 IBAction 来响应用户单击按
我尝试使用 MPI 对矩阵求和来执行此操作,我不知道为什么,但我无法使用 MPI_Send 发送任何类型的数据,但无论我在尝试什么我会收到一条错误消息吗: Sending 3 rows to task
我正在开发一个简单的收件箱/下午系统,我不明白为什么,但我可以显示已发送消息的显示,我可以显示已发送项目的列表,从收件箱查看下午消息,但不能确定我做错了什么,任何提示表示赞赏.. 这是我的代码:
我正在尝试在内容脚本和扩展程序之间传递消息 这是我在内容脚本中的内容 chrome.runtime.sendMessage({type: "getUrls"}, function(response)
我正在尝试将一段分成几个词。我手边有可爱的 nltk.tokenize.word_tokenize(sent),但是 help(word_tokenize) 说,“这个分词器被设计为一次处理一个句子。
我在从设备读取 SMS 消息时遇到问题。获取 URI content://sms/inbox 的内容提供者时,一切都很好。我可以阅读 person 列以在 people 表中找到外键并最终到达联系人及
我知道这个网站上有类似的问题,我已经尝试了一些建议的解决方案,其中一些对之前提出这个问题的人有效。但是,我仍然收到发送两次而不是一次的相同数据。 这是代码: final ProgressDialog
当做programmatic file upload时使用jQuery-File-Upload plugin启用分块后,我无法发送多个文件。 我调用电话的方式如下: fileUploadWidget.
我是一名优秀的程序员,十分优秀!