相关疑难解决方法(0)

像使用NSSortDescriptor的NSInteger一样对NSString值进行排序

我创建了一个排序描述符来排序来自我的服务器的plist响应.这适用于值为9的排序键.超过10个项目我看到突然结果,排序键按顺序排列= 1,10,11,2,3,4,5,6,7,8,9

NSSortDescriptor *aSortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"sort" ascending:YES];
self.myList = [NSMutableArray arrayWithArray:[unsortedList sortedArrayUsingDescriptors:[NSArray arrayWithObject:aSortDescriptor]]];
Run Code Online (Sandbox Code Playgroud)

如何按正确的顺序排列1,2,3,4,5,6,7,8,9,10,11?

iphone cocoa-touch objective-c nssortdescriptor ios

28
推荐指数
5
解决办法
2万
查看次数

按升序排序nsarray

我有一个NSdictonary对象具有以下键值

keys:1.infoKey,2.infoKey,3.infoKey,4.infoKey,5.infoKey,6.infoKey,7.infoKey,8.infoKey,9.infoKey,10.infoKey,11.infoKey

注意它们没有排序,可以是任何顺序,即3.infoKey,7.infoKey,2.infoKey等

我想要做的是排除键值,即1,2,3,4,5,6,7,8,9,10,11 ....这是我到目前为止使用的代码,但每次我做了一个排序,它按照我不想要的方式对其进行排序(见下文)

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
        NSString *stringsPlistPath = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"talkBtns.plist"];

        NSMutableDictionary *dictionary2 = [[NSMutableDictionary alloc] initWithContentsOfFile:stringsPlistPath];


        NSArray *myKeys = [dictionary2 allKeys];

//This didn't give the right results
        //sortedKeys = [myKeys sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];

//This didn't give the right results either
        NSSortDescriptor* sortDescriptor = [NSSortDescriptor sortDescriptorWithKey:nil ascending:YES selector:@selector(localizedCompare:)];
        sortedKeys = [myKeys sortedArrayUsingDescriptors:[NSArray arrayWithObject:sortDescriptor]];

    // ***********
        // GET KEY VALUES TO
        // LOOP OVER
        // ***********
        /* */
        for (int i = 0; i < [sortedKeys count]; …
Run Code Online (Sandbox Code Playgroud)

iphone xcode ipad ios

2
推荐指数
1
解决办法
3408
查看次数

如何使用amount将包含对象的NSMutableArray排序为数据

我有一个NSMutableArray,它包含对象作为数据,它包含三个值,即日期,名称和数量.

所以我的数组看起来像这样

date   name   amount
08/12  atest  1000
08/13  btest  200
08/14  ctest  3000
08/15  dtest  4000
08/13  etest  5000
Run Code Online (Sandbox Code Playgroud)

现在我正在使用此代码对数据进行排序

金额

[tableAry sortUsingDescriptors:[NSArray arrayWithObject:
[NSSortDescriptor sortDescriptorWithKey:@"amount" 
ascending:NO selector:@selector(caseInsensitiveCompare:)]]];
Run Code Online (Sandbox Code Playgroud)

但它说我的200记录大于1000记录排序数据是这样的:

5000
4000
3000
200
1000
Run Code Online (Sandbox Code Playgroud)

iphone ios

1
推荐指数
1
解决办法
199
查看次数

标签 统计

ios ×3

iphone ×3

cocoa-touch ×1

ipad ×1

nssortdescriptor ×1

objective-c ×1

xcode ×1