- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我当前正在尝试分页 Twitter Feed,但是当我尝试添加分页到现有 NSMutableArray 时收到的新项目时,我收到此错误:
Floadt[28482:2207263] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[__NSCFArray insertObject:atIndex:]: mutating method sent to immutable object'
*** First throw call stack:
(
0 CoreFoundation 0x0000000106263c65 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x00000001059a0bb7 objc_exception_throw + 45
2 CoreFoundation 0x0000000106263b9d +[NSException raise:format:] + 205
3 CoreFoundation 0x000000010625c46a -[__NSCFArray insertObject:atIndex:] + 106
4 CoreFoundation 0x0000000106186923 -[NSMutableArray insertObjects:count:atIndex:] + 179
5 CoreFoundation 0x0000000106186654 -[NSMutableArray insertObjectsFromArray:range:atIndex:] + 372
6 CoreFoundation 0x0000000106186454 -[NSMutableArray addObjectsFromArray:] + 612
7 Floadt 0x0000000102375d89 __57-[TwitterTableViewController fetchNextTwitterPageWithID:]_block_invoke + 217
8 Floadt 0x0000000102348e43 __64-[AFJSONRequestOperation setCompletionBlockWithSuccess:failure:]_block_invoke91 + 51
9 libdispatch.dylib 0x000000010844d186 _dispatch_call_block_and_release + 12
10 libdispatch.dylib 0x000000010846c614 _dispatch_client_callout + 8
11 libdispatch.dylib 0x0000000108454a1c _dispatch_main_queue_callback_4CF + 1664
12 CoreFoundation 0x00000001061cb1f9 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
13 CoreFoundation 0x000000010618cdcb __CFRunLoopRun + 2043
14 CoreFoundation 0x000000010618c366 CFRunLoopRunSpecific + 470
15 GraphicsServices 0x0000000107d4ba3e GSEventRunModal + 161
16 UIKit 0x00000001046d4900 UIApplicationMain + 1282
17 Floadt 0x000000010242d46f main + 111
18 libdyld.dylib 0x00000001084a0145 start + 1
19 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
分页 JSON 完全正常返回。我只想在用户滚动到 TableView 底部时将分页项目添加到原始项目下方。
检索分页推文的方法
-(void)fetchNextTwitterPageWithID:(NSString *)objectID {
self.twitterClient = [[AFOAuth1Client alloc] initWithBaseURL:[NSURL URLWithString:@"https://api.twitter.com/1.1/"] key:@"tA5TT8uEtg88FwAHnVpBcbUoq" secret:@"L5whWoi91HmzjrE5bNPNUgoMXWnImvpnkIPHZWQ4VmymaoXyYV"];
NSDictionary *parameters = @{
@"max_id" :objectID
};
AFOAuth1Token *twitterToken = [AFOAuth1Token retrieveCredentialWithIdentifier:@"TwitterToken"];
[self.twitterClient setAccessToken:twitterToken];
[self.twitterClient registerHTTPOperationClass:[AFJSONRequestOperation class]];
[self.twitterClient getPath:@"statuses/home_timeline.json" parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSMutableArray *responseArray = (NSMutableArray *)responseObject;
NSLog(@"Response: %@", responseObject);
tweets = [tweets copy];
[tweets addObjectsFromArray:responseArray];
[self.tableView reloadData];
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error: %@", error);
}];
}
推特用户查询方法
- (void)lookupTwitterUser:(NSString *)user {
self.twitterClient = [[AFOAuth1Client alloc] initWithBaseURL:[NSURL URLWithString:@"https://api.twitter.com/1.1/"] key:@"tA5TT8uEtg88FwAHnVpBcbUoq" secret:@"L5whWoi91HmzjrE5bNPNUgoMXWnImvpnkIPHZWQ4VmymaoXyYV"];
NSDictionary *parameters = @{
@"screen_name" :user
};
AFOAuth1Token *twitterToken = [AFOAuth1Token retrieveCredentialWithIdentifier:@"TwitterToken"];
[self.twitterClient setAccessToken:twitterToken];
[self.twitterClient registerHTTPOperationClass:[AFJSONRequestOperation class]];
[self.twitterClient getPath:@"users/lookup.json" parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) {
userLookup = responseObject;
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error: %@", error);
}];
}
检测用户是否在页面底部的方法
-(void) tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
if ([tweets count] == (indexPath.row+1)) {
NSDictionary *totalArray = tweets[indexPath.row];
NSString *cellID = [totalArray objectForKey:@"id"];
NSLog(@"%@",cellID);
[self fetchNextTwitterPageWithID:cellID];
}
}
最佳答案
错误信息已经很清楚了。您正在尝试改变不可变数组。根据堆栈跟踪,错误出现在您调用 addObjectsFromArray:
的 fetchNextTwitterPageWithID:
方法中。
可疑行是这一行:
NSMutableArray *responseArray = (NSMutableArray *)responseObject;
responseObject
很可能不是可变数组而是不可变数组。
将行更改为:
NSMutableArray *responseArray = [responseObject mutableCopy];
此外,这一行也是一个问题:
tweets = [tweets copy];
同样,您需要一个可变副本:
tweets = [tweets mutableCopy];
关于ios - 在运行时向 UITableView 添加更多项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30585610/
我有一个如下所示的目录树,我需要使用 Jenkins 将完整的结构上传到 Artifactory。现在,我找不到一种方法将属性分配给“德里”下的所有文件,使其具有 Continent(property
我想编写一个扩展,在加载特定 URL 时将 div 元素添加到页面(例如,当 url 为 http://www....&q=car&aq 时,我希望将包含“car”的 div 元素添加到网页) 我已经
从我的服务器应用程序(Spring Boot 应用程序)使用 apns 推送证书发送推送通知时被卡住了。苹果讨论 here关于我们如何发送带有证书的推送的概述,但没有关于 TLS 通信的技术细节(特别
我有一个具有相同类的 div 列表。每个 div 包含其他 div,.header、.body、.footer。当我将鼠标悬停在一个 div 内的某个元素上时,例如 .header,我需要在同一 di
如何在使用 netbeans 时将数据添加到 JTable。它的后台代码中的 Netbeans 是这样的: jTable1 = new javax.swing.JTable(); jTable1.se
我正在使用 plyr作为 HTML5 视频标签的包装器并使用 Hls.js 流式传输我的 .m3u8 视频。 我在 plyr 上解决了很多问题以启用质量选择器,并遇到了多个 PR,这些 PR 有这个问
我使用 Microsoft bot Framework 并将其部署到 Web Chat,我的 bot 以所需的正确格式打印消息并带有换行符“\n\n”,然后我使用以下教程 https://github
我已经在我的项目中添加了用于 Selenium 测试的 chromedriver 选项,但我不明白 edgedriver 的适当方法。我已经尝试了所有的可能性。 有人可以帮我吗? 谢谢你。
我需要能够在 ckeditor 的工具栏上添加一个下拉列表或按钮,以弹出一个列表,当单击一个列表项时,该列表项的文本将被添加到 ckeditor 的内容中 我还需要能够改变那个列表的内容,比如有一个功
当 bootstrap 3 collapsible 折叠时,如何向 div 添加类?我需要一个在 div 折叠时添加类 darken 的代码。当一个可折叠的关闭时,类 darken 应该被删除 #co
我在 Google map 中有很多标记(大约 3000 个),它们在弹出窗口中带有图标和高级详细信息。这就是为什么 map 打开很晚,所有标记加载也很晚。因为我从数据库加载所有标记列表并使用 for
我有一个我称之为资源的表,当用户连续单击按钮时,我想在 jquery 对话框中显示特定记录。 在我做的表中: "ui-button ui-state-default ui-corner-all", :
我正在使用第三方发送电子邮件,他们允许我通过向通过他们发送的电子邮件添加标题来对我的电子邮件进行分类。 是否可以在异常(exception)电子邮件发送前添加标题?或者至少,我将通过捕获中间件中的异常
我有一个页面,其中包含链接到页面适当部分的 anchor 。我想知道是否有人对如何在单击链接时以及当窗口/页面使用 jQuery 滚动到适当的 div 时切换 anchor 链接的类有任何建议? 例如
我正在使用 HTML、PHP 和 JS 创建一个报告网站。我有几张 table 正在展示。在每个表中有多个行 tr 和许多列 td。我对其进行了设置,以便当我单击其中一个 tr 时,它会获得 sele
我使用 UIWebView 以这样的缅甸字体显示搜索测试 NSString *googleText = @"မြန်မာဘာသာ"; NSString *googleLink = [N
在将其添加为包装器 UIView 的 subview 之前,我尝试使用 Autolayout 创建以下设置到我的 UITableView。 到目前为止,我正在使用以下内容,但一点运气都没有。据我所知,
在迭代 map 时,向 map 添加/删除元素是否安全?请看下面的伪代码: //Pseudo Code //test is a global variable
我编写了一个名为 dragscroll 的 Angular Directive(指令),它根据在 Canvas 上的拖动向右或向左滚动水平溢出元素。 请引用这个fiddle How it works:
在我的 meteor 应用程序中,我的 css 中有以下规则: body { background: #ddd url(../img/bg.png); padding-top: 120
我是一名优秀的程序员,十分优秀!