There is a table, it is filled from the list *.plist , which is based on dictionaries ( NSDictionary ),
about the same format:

 <array> <dict> <key>name</key> <string>Example1</string> <key>type</key> <string>1</string> </dict> <dict> <key>name</key> <string>Example2</string> <key>type</key> <string>2</string> </dict> </array> 

Question: is it possible to filter by clicking on one of the UISegmentedControl buttons
table and display only data with type "1"?
PS: with the withdrawal of all data from the list there are no problems.



    2 answers 2

    Well, as an addition to the laconic "of course you can " @aknew , I will show you how you can do it in another way:

     NSArray *array; // массив, полученный из plist'a NSString *type = @"1"; NSArray *result = [array filteredArrayUsingPredicate: [NSPredicate predicateWithFormat:@"(type == %@)", type]]; 

    (iOS 3.0+, OS X 10.4+)


    Although, personally, I would pre- pack objects with different types in separate arrays - this should be faster than pulling them out of one general each time.

    • gorgeous! I will test it in the evening =) I also thought that I would probably do it over stuffing objects with different types in different arrays, thanks for the hint. - Kobayashi_Maru
    • @Kobayashi_Maru and you can even not in different ways - it’s harder to apply to them in fact - and, for example, in the dictionary, where under the keys "1" , "2" , ... there will be arrays of objects you need. - VioLet
    • I took advantage of different arrays so far, everything turned out, then I'll try with a dictionary. Thanks for the tip-off) - Kobayashi_Maru

    Of course you can, when I pressed the button I would run through the entire array and select the desired type into another array and build a table based on it. Considering that with such a storage method the array is not too large, I do not think that it will take a lot of time.