通过排序按字母顺序排列的数组它是由UIPickerView之前选择 [英] Sorting an array by alphabetical order before it is selected by UIPickerView

查看:105
本文介绍了通过排序按字母顺序排列的数组它是由UIPickerView之前选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新iphone的发展,需要一些指导,做定制iOS中的数组进行排序。我想出现在UIPickerView中的对象进行排序。被传递到UIPickerView的对象是在数组中。

I am new to iphone development and need some guidance to do custom sorting of an array in iOS. I would like to sort the objects that appear in the UIPickerView. The objects that are passed to the UIPickerView are in an array.

当我打印出数组,它看起来像这样:

When I print the array out, it looks like this:

    "<ObjectsInfo: 0x1c5249f0>",
    "<ObjectsInfo: 0x1c524940>",
    "<ObjectsInfo: 0x1c5248e0>",
    "<ObjectsInfo: 0x1c524890>",
    "<ObjectsInfo: 0x1c524840>",
    "<ObjectsInfo: 0x1c524a90>",

当我打印出的第一个对象的名称:

When i print out the first object's name:

    ObjectsInfo *object = [objectModelName objectAtIndex:1];
    NSLog(@"%@",object.str_name);

据打印出:阿尔法

It prints out: Alpha

给出的值是示例。我想以按字母顺序数组objectModelName。

The values given are examples. I would like to sort the array objectModelName in alphabetical order.

我该怎么办呢?

我试过这样:

[objectModelName sortUsingSelector:@selector(compare:)];

我该怎么做自定义排序的基础上的str_name以便它是按字母顺序排列?需要一些指导...真的AP preciate任何帮助...

How do i do custom sorting based on the str_name so that it is in alphabetical order? Need some guidance... Really appreciate any help...

推荐答案

试试这个。

NSArray *sortedArray = [objectModelName sortedArrayUsingComparator:^(ObjectsInfo *firstObject, ObjectsInfo *secondObject) {
            return [firstObject.str_name compare:secondObject.str_name];
        }];

这篇关于通过排序按字母顺序排列的数组它是由UIPickerView之前选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆