只有第一项添加到数组

时间:2014-10-07 14:20:21

标签: ios mkannotation

我有一个for循环,它通过我从Twitter API获得的一系列推文。只要每条推文的坐标不为空,就会使用推文中的screen_name作为标题和推文坐标创建注释。每个注释都添加到一个数组中,当循环结束时,该数组中的注释将添加到地图视图中。我的问题是只有第一条推文被添加为注释。我错过了什么?

STTwitterAPI *twitter = [STTwitterAPI twitterAPIAppOnlyWithConsumerKey:@"key" consumerSecret:@"secret"];

    [twitter verifyCredentialsWithSuccessBlock:^(NSString *username) {

        [twitter getSearchTweetsWithQuery:@"apple" geocode:geoCode lang:nil locale:nil resultType:@"recent" count:@"10" until:nil sinceID:nil maxID:nil includeEntities:nil callback:nil successBlock:^(NSDictionary *searchMetadata, NSArray *statuses) {

            tweetsArray = [NSMutableArray arrayWithArray:statuses];
            NSLog(@"tweetsArray: %@", tweetsArray);

            for (int i = 0; i < [tweetsArray count]; i++) {
                NSDictionary *t = tweetsArray[i];
                tweetAnnotation = [[MKPointAnnotation alloc]init];

                NSArray *tweetLocation = [[t valueForKey:@"geo"]valueForKey:@"coordinates"];
                NSLog(@"Tweet Location: %@", tweetLocation);

                if ([tweetLocation isEqual:[NSNull null]]) {
                    continue;
                }
                else {
                    double lat = [[tweetLocation objectAtIndex:0]doubleValue];
                    double longitude = [[tweetLocation objectAtIndex:1]doubleValue];
                    locationCoord.latitude = lat;
                    locationCoord.longitude = longitude;
                    NSLog(@"Lat: %.8f, Long: %.8f", lat, longitude);

                    twitterName = [t valueForKeyPath:@"user.screen_name"];
                    NSLog(@"Twitter name: %@", twitterName);
                    tweetAnnotation.title = twitterName;

                    tweetAnnotation.coordinate = locationCoord;
                    [tweetLocationsArray addObject:tweetAnnotation];
                }
            }

            [tweetMap addAnnotations:tweetLocationsArray];

        } errorBlock:^(NSError *error) {

            NSLog(@"%@", error.debugDescription);

        }];

    } errorBlock:^(NSError *error) {

        NSLog(@"%@", error.debugDescription);

    }];

0 个答案:

没有答案