开发者

remove array entry with empty values

I have an array with a lot of empty values and I want to remove them from the array....

    NSMutableArray *entry = [self.selectedRow allValues];

for (int i = 0 ; i < [entry count] ; i++) {

    NSLog(@"count: %@", [entry objectAtIndex: i]);
    NSLog(@"point: %@", [selectedRow valueForKey:[entry objectAtIndex:i]]);
    if([[selectedRow valueForKey:[entry objectAtIndex: i]] length] < 2){
        [selectedRow removeObject开发者_JS百科AtIndex: i];
    }
}

the < 2 is because there are some values there not really empty.....

for some reason [entry valueForKey:[entry objectAtIndex:i]]] is empty

and i get the exeption -[__NSCFDictionary removeObjectAtIndex:]: unrecognized selector sent to instance 0x7021510 but there is no dictionary involved ther are only arrays.

and when i count down for (int i = [entry count -1; i = 0; i--]){ the loop isn't even called?!?

I hope someone can help me with that....

EDIT:

Is not what initialy wanted but some how it works better that way... I check the length for the valueForKey when I parse the file so i reduce the file size for more then the half and it works pretty good.....


Try this:

NSMutableArray *entry = [NSMutableArray arrayWithArray:[self.selectedRow allValues]];

because [self.selectedRow allValues] likely returns an NSArray you can't just pretend it's Mutable.

OH. and furthermore self.selectedRow looks like an NSDictionary. Try removeObjectForKey: instead.


Should be,

for (int i = [entry count] -1; i > 0; i--]){ }

And try,

for (int i = 0 ; i < [selectedRow count]; i++) {
    if([[selectedRow objectAtIndex: i] count] < 2){
        [selectedRow removeObjectAtIndex: i];
    }
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜