Iphone Twitter搜索标签
我正在尝试使用Twitter框架分析tweet,因此我编写了以下代码,它工作正常,但不是同步的 现在我正在尝试从iOS获取所有推文 我使用了以下代码来获取iOS标签的搜索结果:Iphone Twitter搜索标签,iphone,ios,objective-c,xcode,ios5,Iphone,Ios,Objective C,Xcode,Ios5,我正在尝试使用Twitter框架分析tweet,因此我编写了以下代码,它工作正常,但不是同步的 现在我正在尝试从iOS获取所有推文 我使用了以下代码来获取iOS标签的搜索结果: -(void)fetchResults { // Do a simple search, using the Twitter API TWRequest *request = [[TWRequest alloc] initWithURL:[NSURL URLWithString:
-(void)fetchResults
{
// Do a simple search, using the Twitter API
TWRequest *request = [[TWRequest alloc] initWithURL:[NSURL URLWithString:
@"http://search.twitter.com/search.json?q=iOS%20&rpp=20&with_twitter_user_id=true&result_type=recent"]
parameters:nil requestMethod:TWRequestMethodGET];
// Notice this is a block, it is the handler to process the response
[request performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error)
{
if ([urlResponse statusCode] == 200)
{
// The response from Twitter is in JSON format
// Move the response into a dictionary and print
NSError *error;
dict = [NSJSONSerialization JSONObjectWithData:responseData options:0 error:&error];
NSLog(@"Twitter response: %@", [dict description]);
[self filterTweets];
}
else
NSLog(@"Twitter error, HTTP response: %i", [urlResponse statusCode]);
}];
}
结果我得到了这个:
Twitter response: {
"completed_in" = "0.007";
"max_id" = 333837474914766848;
"max_id_str" = 333837474914766848;
page = 1;
query = quranRadios;
"refresh_url" = "?since_id=333837474914766848&q=quranRadios&result_type=recent";
results = (
{
"created_at" = "Mon, 13 May 2013 06:53:51 +0000";
"from_user" = YousefMutawe;
"from_user_id" = 324385406;
"from_user_id_str" = 324385406;
"from_user_name" = "Yousef N Mutawe \Uf8ff";
geo = "<null>";
id = 333837474914766848;
"id_str" = 333837474914766848;
"iso_language_code" = pt;
metadata = {
"result_type" = recent;
};
"profile_image_url" = "http://a0.twimg.com/profile_images/1533729607/20090719526_normal.jpg";
"profile_image_url_https" = "https://si0.twimg.com/profile_images/1533729607/20090719526_normal.jpg";
source = "<a href="http://twitter.com/download/iphone">Twitter for iPhone</a>";
text = "Testing #quranRadios @Mkalatrash";
},
{
"created_at" = "Sun, 12 May 2013 13:09:43 +0000";
"from_user" = YousefMutawe;
"from_user_id" = 324385406;
"from_user_id_str" = 324385406;
"from_user_name" = "Yousef N Mutawe \Uf8ff";
geo = "<null>";
id = 333569679484416000;
"id_str" = 333569679484416000;
"iso_language_code" = et;
metadata = {
"result_type" = recent;
};
"profile_image_url" = "http://a0.twimg.com/profile_images/1533729607/20090719526_normal.jpg";
"profile_image_url_https" = "https://si0.twimg.com/profile_images/1533729607/20090719526_normal.jpg";
source = "<a href="http://twitter.com/download/iphone">Twitter for iPhone</a>";
text = "#quranRadios :)";
}
);
"results_per_page" = 20;
"since_id" = 0;
"since_id_str" = 0;
我不确定我做的事情是否正确,那么你会建议我做什么?我如何使它同步
我是编程iOS新手,请提供建议。
谢谢
您是对的,异步获取tweet并在主线程重新加载UI。没关系。为什么要使它同步?不应该同步吗?也许是因为我想得到新的推特!!你是说同步、同步还是异步?。他们之间有很大的不同。您要找的是哪一个,代码的哪一部分导致了问题?忘记同步任何东西!!只要tableview滚动,我就可以加载更多的结果。
-(void)filterTweets
{
NSArray *results = [dict objectForKey:@"results"];
//Loop through the results
int x =0;
for (NSDictionary *tweet in results)
{
// Get the tweet
NSString *twittext = [tweet objectForKey:@"text"];
NSString *twitPic = [tweet objectForKey:@"profile_image_url"];
NSString *userName = [tweet objectForKey:@"from_user"];
// Save the tweet to the twitterText array
[tweetsInfo addObject:(twittext)];
[tweetPics addObject:(twitPic)];
[imagesArray addObject:[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:[tweetPics objectAtIndex:x]]]]];
[userNameTweet addObject:userName];
x++;
//NSLog(@"tweet ooooooo ======> %@",twitPic);
countMe++;
}
[tweetsTable reloadData];
}