Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/121.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 代码可以在64位iPhone上运行,但不能在任何其他手机上运行。。。为什么不呢?_Ios_Objective C_Algorithm - Fatal编程技术网

Ios 代码可以在64位iPhone上运行,但不能在任何其他手机上运行。。。为什么不呢?

Ios 代码可以在64位iPhone上运行,但不能在任何其他手机上运行。。。为什么不呢?,ios,objective-c,algorithm,Ios,Objective C,Algorithm,经过实验后,我意识到这段代码只适用于64位iPhone,而不适用于其他手机。不在iPad上,不在我自己的设备(iPhone 5)上,也不在任何未指定为64位的设备上。为什么会这样 - (void)loadVenues { NSString *latLon = @"30, -120"; NSString *clientID = kCLIENTID; NSString *clientSecret = kCLIENTSECRET; NSDictionary *que

经过实验后,我意识到这段代码只适用于64位iPhone,而不适用于其他手机。不在iPad上,不在我自己的设备(iPhone 5)上,也不在任何未指定为64位的设备上。为什么会这样

- (void)loadVenues {
    NSString *latLon = @"30, -120";
    NSString *clientID = kCLIENTID;
    NSString *clientSecret = kCLIENTSECRET;


    NSDictionary *queryParams = @{@"ll" : latLon,
                                  @"client_id" : clientID,
                                  @"client_secret" : clientSecret,
                                  @"categoryId" : @"4bf58dd8d48988d1e0931735",
                                  @"v" : @"20140118"};

    [[RKObjectManager sharedManager] getObjectsAtPath:@"/v2/venues/search"
                                           parameters:queryParams
                                              success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) 
    {
        _venues = mappingResult.array;

        NSMutableArray *temp = [(NSArray*)_venues mutableCopy];
        Venue *holder;
        for (int i = 0; i < _venues.count; i++) {
            for (int j = 0; j < i; j++) {
                if (((Venue *) [temp objectAtIndex:i]).location.distance < ((Venue *) [temp objectAtIndex:j]).location.distance) {
                    holder = [temp objectAtIndex:j];
                    [temp replaceObjectAtIndex:j withObject:[temp objectAtIndex:i]];
                    [temp replaceObjectAtIndex:i withObject:holder];
                }
            }
        }

        _venues = temp;
        [self.tableView reloadData];

    } failure:^(RKObjectRequestOperation *operation, NSError *error) {
        NSLog(@"What do you mean by 'there is no coffee?': %@", error);
    }];
}
-(无效)加载场地{
NSString*latLon=@“30,-120”;
NSString*clientID=kCLIENTID;
NSString*clientSecret=kCLIENTSECRET;
NSDictionary*queryParams=@{@“ll”:latLon,
@“客户id”:客户id,
@“客户机密”:客户机密,
@“类别ID:@“4bf58dd8d48988d1e0931735”,
@“v:@“20140118”};
[[RKObjectManager sharedManager]getObjectsAtPath:@”/v2/victions/search
参数:queryParams
成功:^(RKObjectRequestOperation*操作,RKMappingResult*映射结果)
{
_场馆=mappingResult.array;
NSMUTABLEARRY*temp=[(NSArray*)\U mutableCopy];
场地*持有人;
对于(int i=0;i<\u.count;i++){
对于(int j=0;j
我并不认为您的排序算法很糟糕,但为什么不使用内置的排序算法来简化代码呢

NSMutableArray *arrayToSort = (NSMutableArray *)mappingResult.array;
[arrayToSort sortUsingComparator:^NSComparisonResult(id obj1, id obj2) {
    Venue *venue1 = obj1;
    Venue *venue2 = obj2;
    double value1 = venue1.location.distance;
    double value2 = venue2.location.distance;
    if (value1 > value2)
        return NSOrderedAscending;
    else if (value1 < value2)
        return NSOrderedDescending;
    else
        return NSOrderedSame;
}];
NSMutableArray*arrayToSort=(NSMutableArray*)mappingResult.array;
[ArraySort sortUsingComparator:^n比较结果(id obj1,id obj2){
地点*venue1=obj1;
地点*venue2=obj2;
双值1=venue1.location.distance;
双值2=venue2.location.distance;
如果(值1>值2)
回报率下降;
否则如果(值1<值2)
退而求其次;
其他的
返回指定名称;
}];

好的,我想我知道问题出在哪里了。你说过。距离是一种
NSNumber
类型。所以你要做的是比较两个物体。您要做的是比较两个浮点值。因此,您应该将if语句代码修改为:

if (((Venue *) [temp objectAtIndex:i]).location.distance.floatValue < ((Venue *) [temp objectAtIndex:j]).location.distance.floatValue)
if(((场馆*)[temp objectAtIndex:i]).location.distance.floatValue<((场馆*)[temp objectAtIndex:j]).location.distance.floatValue)

我还建议您使用@doctoroder的修订版

到底是什么不起作用?异常,逻辑错误?你没有“排序算法”,你使用的是“排序算法”@theMonster我没有收到任何异常错误,只是数组似乎没有按正确的顺序加载。它似乎是以随机序列加载的。因此,它正确地清除/替换了您不需要的数据。但是数组上的排序不是您想要的吗?另外,排序算法的目标是什么?我猜是为了找到最近的地点?还是按距离对场馆进行排序?@theMonster根本没有排序。但是,数组是由for循环操纵的,只是没有按照我希望的方式操纵。太好了,谢谢!为什么32位iPhone不支持这个功能?它是受支持的,我不知道你为什么认为它不支持。但是如果这是正确的答案,那么如果你接受它,那就太好了:)。