我的数组元素是这样的
150,
150,
150,
571,
571,
571,
692,
692,
692,
123,
123,
123,
144,
144,
144,
147,
147,
147,
155,
155,
155,
542,
542,
542,
548,
548,
548,
551,
551,
551
我需要显示所有元素,但不是重复显示相同的元素,它必须在 UItableView 中打印。这是我的代码,
NSArray *array=[jsonarray valueForKey:@"ID"];
cell.textLabel.text=[array objectAtIndex:indexPath.row] ;
这里我的 jsonarray 有多个字段,其中 ID 是一个。请指导..
最佳答案
您可以使用 NSSet。来自 Apple 的文档:NSSet 声明了不同对象的静态集合的编程接口(interface)。像这样:
NSSet *mySet = [NSSet setWithArray:array];
或者:
NSSet *mySet = [NSSet alloc]initWithArray:array];
(为完整性而编辑)然后:
array = [mySet allObjects]; //now you can continue using the array as previously
关于objective-c - 如何避免 NSArray 中的重复元素并在 TableView 单元格中打印,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11739111/