您好,我在我的应用程序中使用轮播来显示推文。虽然这个过程花费了很多时间来显示视图控制器,所以我使用 GDC 来加载视图控制器,然后在下载推文时更新轮播视图
- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index reusingView:(UIView *)view
{
if (!view)
{
//load new item view instance from nib
//control events are bound to view controller in nib file
view = [[[NSBundle mainBundle] loadNibNamed:@"Empty" owner:self options:nil] lastObject];
//[self performSelectorInBackground:@selector(loadthetweets) withObject:nil ];
//[self performSelectorInBackground:@selector(loadfromtheweb:) withObject:nil];
//[self performSelectorOnMainThread:@selector(loadthetweets) withObject:nil waitUntilDone:YES];
//[self performSelectorInBackground:@selector(loadthetweets) withObject:nil];
/*
NSString *feedname=@"http://api.twitter.com/1/statuses/user_timeline.json?include_entities=true&include_rts=true&screen_name=shoplog1&count=20";
NSURL *feedURL =[NSURL URLWithString:feedname];
//The JSON Part
NSData *data =[NSData dataWithContentsOfURL:feedURL];
NSError* error;
_tweets= [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves
error:&error];
maintext=[[_tweets objectAtIndex:index]objectForKey:@"text"];
NSArray *piecesOfOriginalString = [maintext componentsSeparatedByString:@"http"];
NSString *firstetxt=[piecesOfOriginalString objectAtIndex:0];
NSLog(@"The first text: %@",firstetxt);
NSString *link=[@"http" stringByAppendingString:[piecesOfOriginalString objectAtIndex:1]];
linktogo=[NSURL URLWithString:link];
text.text=firstetxt;
NSLog(@"The link text: %@",link);
//NSDictionary *new =[[[tweets objectAtIndex:index]objectForKey:@"entities"]objectForKey:@"urls"];
NSDictionary *retweeted=[[_tweets objectAtIndex:index]objectForKey:@"retweeted_status"];
if (retweeted) {
NSString *urlll=[[[[_tweets objectAtIndex:index]objectForKey:@"retweeted_status"]objectForKey:@"user"]objectForKey:@"profile_image_url"];
NSURL *iiii=[NSURL URLWithString:urlll];
usericon.image=[UIImage imageWithData:[NSData dataWithContentsOfURL:iiii]];
username.text=[[[[_tweets objectAtIndex:index]objectForKey:@"retweeted_status"]objectForKey:@"user"]objectForKey:@"screen_name"];
}else{
username.text=@"Shoplog";
usericon.image=[UIImage imageNamed:@"MyIcon copy_57.png"];
}
*/
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
[Provideractivity startAnimating];
[ContentActivity startAnimating];
dispatch_queue_t concurrentQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_async(concurrentQueue, ^{
[self loadthetweets];
//[self loadfromtheweb:[NSNumber numberWithUnsignedInt:index ]];
dispatch_async(dispatch_get_main_queue(), ^{
//[self loadfromtheweb:[NSNumber numberWithUnsignedInt:index ]];
maintext=[[_tweets objectAtIndex:index]objectForKey:@"text"];
NSArray *piecesOfOriginalString = [maintext componentsSeparatedByString:@"http"];
NSString *firstetxt=[piecesOfOriginalString objectAtIndex:0];
NSLog(@"The first text: %@",firstetxt);
NSString *link=[@"http" stringByAppendingString:[piecesOfOriginalString objectAtIndex:1]];
linktogo=[NSURL URLWithString:link];
text.text=firstetxt;
NSLog(@"The link text: %@",link);
//NSDictionary *new =[[[tweets objectAtIndex:index]objectForKey:@"entities"]objectForKey:@"urls"];
NSDictionary *retweeted=[[_tweets objectAtIndex:index]objectForKey:@"retweeted_status"];
if (retweeted) {
NSString *urlll=[[[[_tweets objectAtIndex:index]objectForKey:@"retweeted_status"]objectForKey:@"user"]objectForKey:@"profile_image_url"];
username.text=[[[[_tweets objectAtIndex:index]objectForKey:@"retweeted_status"]objectForKey:@"user"]objectForKey:@"screen_name"];
NSURL *iiii=[NSURL URLWithString:urlll];
usericon.image=[UIImage imageWithData:[NSData dataWithContentsOfURL:iiii]];
}else{
username.text=@"Shoplog";
usericon.image=[UIImage imageNamed:@"MyIcon copy_57.png"];
}
[ContentActivity stopAnimating];
[ContentActivity hidesWhenStopped];
[Provideractivity stopAnimating];
[Provideractivity hidesWhenStopped];
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
});
});
}
return view;
}
这里的问题是 Carousel 的第 11 个元素已正确更新,其余部分为空白,我不知道为什么。
有人可以帮忙吗?