[英]How to remove particular value into NSMutableArray using objective C?
I am facing some empty values adding into NSMutableArray issue. 我面临一些添加到NSMutableArray问题中的空值。 I need to remove that one before loading on tableview because Its adding empty row on table.
我需要在加载tableview之前将其删除,因为它在表上添加了空行。
Into my array (like: "") this type of empty quotes adding. 将这种类型的空引号添加到我的数组中(例如:“”)。 Please help me.
请帮我。
you can write a category on NSMutableArray
, and validate the string while adding it to array 您可以在
NSMutableArray
上编写一个类别,并在将字符串添加到数组时验证该字符串
your implementation should look like this, 您的实现应如下所示,
#import "NSMutableArray+Validation.h"
@implementation NSMutableArray (Validation)
- (void)addObjectIfItsValidString:(id)anObject
{
if (anObject && [anObject isKindOfClass:[NSString class]] && ((NSString *)anObject).length > 0) {
[self addObject:anObject];
}
}
@end
NSMutableArray已经具有内置的removeObjectIdenticalTo
方法,该方法删除所有出现的特定对象,因此您可以执行以下操作:
[array removeObjectIdenticalTo:@""]
Try this 尝试这个
[anArray removeObjectAtIndex: index];
[anArray removeObject: item];
[anArray removeLastObject];
Hope it helps. 希望能帮助到你。
Try this it might help you. 试试这个可能对您有帮助。
for (int i=0;i<array.count;i++) {
NSString *string = array[i];
if(string.length==0||[string isEqualToString:@""]){
[array removeObjectAtIndex:i];
}
}
int index = [arr indexOfObject:@""];
[arr removeObjectAtIndex:index];
Try this:
NSMutableSet* set = [NSMutableSet setWithArray:array];
[set removeObject:@""];
NSArray *result =[set allObjects];
NSLog(@"%@",result);
and If you have array of dictionary so you can try this: 并且如果您有字典数组,则可以尝试以下操作:
NSArray* keysToGo = [myDictionary allKeysForObject: @""];
[myDictionary removeObjectsForKeys: keysToGo];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.