如果 Objective C 中的值为 NULL,则删除数组中的行
remove row in array if value is NULL in Objective C
如何从 objective c
中的 Nsarray 中删除空值或 Null 值
这里是我的示例代码:
cell.subtitleLbl.text = [[chapterArray objectAtIndex:indexPath.row] valueForKey:@"person"];
选择-1
// mainArray array is your current array
NSMutableArray *tempArray = [[NSMutableArray alloc]init];
for (int i = 0; i < [mainArray count]; i++) {
id obj = [mainArray objectAtIndex:i];
if (![obj isKindOfClass:[NSNull class]]) { // or if (![obj isKindOfClass:[[NSNull null]class]]) {
[tempArray addObject:obj];
}
}
NSLog(@"%@",tempArray);
选择-2
[yourarrayName removeObjectIdenticalTo:[NSNull null]];
选择 3
使用谓词
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"NOT (SELF CONTAINS %@)", @"<null>"];
[yourarrayname filterUsingPredicate:predicate];
选择-4
如果你使用字典数组
NSMutableArray *newarray=[NSMutableArray array];
for (NSDictionary *dictionary in presentArrray)
{
if (dictionary[key] != [NSNull null]) {
[newarray addObject:dictionary];
}
}
使用可变数组
从中删除空对象
[arrayName removeObjectIdenticalTo:[NSNull null]];
如何从 objective c
中的 Nsarray 中删除空值或 Null 值这里是我的示例代码:
cell.subtitleLbl.text = [[chapterArray objectAtIndex:indexPath.row] valueForKey:@"person"];
选择-1
// mainArray array is your current array
NSMutableArray *tempArray = [[NSMutableArray alloc]init];
for (int i = 0; i < [mainArray count]; i++) {
id obj = [mainArray objectAtIndex:i];
if (![obj isKindOfClass:[NSNull class]]) { // or if (![obj isKindOfClass:[[NSNull null]class]]) {
[tempArray addObject:obj];
}
}
NSLog(@"%@",tempArray);
选择-2
[yourarrayName removeObjectIdenticalTo:[NSNull null]];
选择 3
使用谓词
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"NOT (SELF CONTAINS %@)", @"<null>"];
[yourarrayname filterUsingPredicate:predicate];
选择-4
如果你使用字典数组
NSMutableArray *newarray=[NSMutableArray array];
for (NSDictionary *dictionary in presentArrray)
{
if (dictionary[key] != [NSNull null]) {
[newarray addObject:dictionary];
}
}
使用可变数组
从中删除空对象
[arrayName removeObjectIdenticalTo:[NSNull null]];