Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/120.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 只有第一项被添加到数组中_Ios_Mkannotation - Fatal编程技术网

Ios 只有第一项被添加到数组中

Ios 只有第一项被添加到数组中,ios,mkannotation,Ios,Mkannotation,我有一个for循环,它通过我从twitterapi获得的一系列tweet。只要每个tweet的坐标不为null,就会创建一个注释,其中tweet的屏幕名称作为tweet的标题和坐标。每个注释都将添加到一个数组中,循环完成后,该数组中的注释将添加到地图视图中。我的问题是,只有第一条tweet被添加为注释。我错过了什么 STTwitterAPI *twitter = [STTwitterAPI twitterAPIAppOnlyWithConsumerKey:@"key" consumerSecre

我有一个for循环,它通过我从twitterapi获得的一系列tweet。只要每个tweet的坐标不为null,就会创建一个注释,其中tweet的屏幕名称作为tweet的标题和坐标。每个注释都将添加到一个数组中,循环完成后,该数组中的注释将添加到地图视图中。我的问题是,只有第一条tweet被添加为注释。我错过了什么

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);

    }];

你有没有调试过这个?在将项目添加到数组的位置放置一个断点,然后找出为什么只调用一次,然后再次检查NSArray*状态是否包含多个对象,以及tweetsArray是否包含所有这些对象。你知道这一点吗?我遇到了一个类似的问题,我从NSMutableArray添加注释,但只添加了第一个注释。