简体   繁体   English

如何使用目标C将特定值删除到NSMutableArray中?

[英]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.

相关问题 如何从目标c中的NSMutablearray中删除空值? - how to remove the null value from NSMutablearray in objective c? 如何使用Objective-C删除Firebase中的特定键? - How to remove particular key in Firebase using Objective-C? 如何将NSMutableArray添加到NSMutableArray Objective-c - How to add an NSMutableArray to an NSMutableArray Objective-c 目标 C - 如何检查 NSMutableArray 的所有元素 (NSMutableString) 是否都有值? - Objective C - How check if all elements (NSMutableString) of NSMutableArray has a value? 如何在Objective c的UITableview中获取NSMutableArray而不是Index的实际值 - How to get actual value of NSMutableArray not Index in UITableview in Objective c 如何使用Objective-C使用两个NSMutableArray填充Expandable TableView - How to populate, Expandable TableView with two NSMutableArray using objective-c Objective-C:如何使用它们的标签对UIButton的NSMutableArray进行排序 - Objective-c: how to sort a NSMutableArray of UIButtons using their tags 目标C-无法更改NSMutableArray中的值 - Objective C - Can't change value in NSMutableArray 如何在NSMutableArray中对对象进行分组并在Objective-C中划分为单独的NSMutableArray - How to group object in NSMutableArray and divide to separate NSMutableArray in Objective-C 如何将NSMutableArray存储到Objective-C中的另一个NSMutableArray - How to store an NSMutableArray to another NSMutableArray in Objective-C
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM