开发者

How to remove the repeated data in the pickerview in iphone?

开发者 https://www.devze.com 2023-03-21 18:39 出处:网络
I have array with 10 data. I\'m showing the value of that array in the pickerview. Out of 10 values in the array 4 data are same for example there are apple for 4 times. How to remove the repeat开发者

I have array with 10 data. I'm showing the value of that array in the pickerview. Out of 10 values in the array 4 data are same for example there are apple for 4 times. How to remove the repeat开发者_开发问答ed data and show only one time apple in the picker.


you can remove duplicate data from your array like:

NSArray *cleanedArray = [[NSSet setWithArray:yourArray] allObjects];


Take another Array and insert distinct value in that, then use that array as your data source for the picker.


Try this before assigning it to picker-view.

for (int i=0; i<[array count]; i++)
        for (int j=i+1; j<[array count]; j++)
            if ( [[array objectAtIndex:i] isEqual:[array objectAtIndex:j]])
                [array removeObjectAtIndex:j];
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号