我正在尝试在UITableView
.
代码 :-
- (void)requestTimeline:(int)count
{
NSURL *url = [NSURL URLWithString:@"http://api.twitter.com/1/statuses/user_timeline.json"];
NSMutableDictionary *parameters = [[NSMutableDictionary alloc] init];
[parameters setObject:@"abc" forKey:@"screen_name"];
[parameters setObject:@"20" forKey:@"count"];
[parameters setObject:@"1" forKey:@"include_entities"];
TWRequest *request = [[TWRequest alloc] initWithURL:url parameters:parameters requestMethod:TWRequestMethodGET];
[request performRequestWithHandler:^(NSData *responseData1, NSHTTPURLResponse *urlResponse, NSError *error)
{
if (responseData1 != nil)
{
NSError *error = nil;
self.itemsToDisplay = [NSJSONSerialization JSONObjectWithData:responseData1 options:NSJSONReadingMutableLeaves error:&error];
if (self.itemsToDisplay != nil)
{
[self.tableView reloadData];
}
else
{
NSLog(@"Error serializing response data %@ with user info %@.", error, error.userInfo);
}
}
else
{
NSLog(@"Error requesting timeline %@ with user info %@.", error, error.userInfo);
}
}];
}
self
是UITableViewController
的子类。
由于阻塞,推特请求将在另一个线程上执行,而不是在主线程上。这就是它崩溃的原因。
//TWRequest.h
// Issue the request. This block is not guaranteed to be called on any particular thread.
- (void)performRequestWithHandler:(TWRequestHandler)handler;
崩溃报告:-
bool _WebTryThreadLock(bool), 0xa8e4f50: 试图从主线程或web线程以外的线程获取web lock。这可能是从辅助线程调用 UIKit 的结果。现在崩溃...
如何解决这个问题?
谢谢...