0

こんにちは、アプリでカルーセルを使用してツイートを表示しました。ビューコントローラーが表示されるまでのプロセスには時間がかかりましたが、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;

}

ここで間違っているのは、カルーセルの 11 番目の要素が正しく更新され、残りが空白で、その理由がわかりません。

誰か助けてくれませんか?

4

2 に答える 2

0

ご回答有難うございます !、ツイートのダウンロードを (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index reusingView:(UIView *)view ビューコントローラーの initfromnib 関数の外部の関数に入れ、呼び出すことができましたが、現在は時間がかかりません!

于 2013-05-01T07:58:07.273 に答える
0

あなたのif (!view) {...}ブロックでは、ビューを作成するだけで、構成しないでください。この if ステートメントの前後でビューを構成します。渡されたビューは- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index reusingView:(UIView *)viewすでに作成されている可能性があり、その場合は if ブロックに入らず、if が構成されないため、ツイートは読み込まれません。

于 2013-03-29T15:50:01.217 に答える