English 中文(简体)
当删除空字符串元素时, 为什么删除对象会丢弃例外?
原标题:Why does removeObject throw an exception when removing elements that are empty strings?

我正试图用下列方法从一个NSMuvatableAray天体中删除任何含有空间的元素:

[searchCriteria removeObject:[NSString stringWithString:@" "]];

我得到了一个例外," -[ NSArayI 移除目标::: 未知的选择器被发送到实例中。"我做错了什么?

EDIT: OK, so I tried the following

NSPredicate* predicate = [NSPredicate predicateWithFormat:@"SELF NOT CONTAINS    "];
NSArray *nonEmptyElements = [searchCriteria filteredArrayUsingPredicate: predicate];

并获取错误, 无法解析格式字符串“ 自己不包含” 。

我该如何指定一个空字符串, 排在内装物之后?

最佳回答

你有一个普通的NSANRAR,而不是NSMMableArAR。也许在某个时候,你认为你曾经被复制或序列的NSNSMETRARAR, 导致一个不可改变的阵列。

顺便说一句,正如Lauteris所说, 这将过滤只包含一个空格的字符串。 要过滤任意一个空格的字符串, 您会希望按照他所说的方式进行。 如果您想要过滤出单空格字符串, 写< code\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

问题回答

You should use an NSPredicate to filter out any items with space. See here how to do this: https://stackoverflow.com/a/1057202/312312

您应该使用自我包含的上游, 而不是以示例所用的自我开头 。





相关问题
Asynchronous request to the server from background thread

I ve got the problem when I tried to do asynchronous requests to server from background thread. I ve never got results of those requests. Simple example which shows the problem: @protocol ...

objective-c: Calling a void function from another controller

i have a void, like -(void) doSomething in a specific controller. i can call it in this controller via [self doSomething], but i don t know how to call this void from another .m file. I want to call ...

ABPersonViewController Usage for displaying contact

Created a View based Project and added a contact to the AddressBook using ABAddressBookRef,ABRecordRef now i wanted to display the added contact ABPersonViewController is the method but how to use in ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

NSUndoManager and runModalForWindow:

I have a simple Core Data app which displays a list of entities in the main window. To create or add new entities, I use a second modal window with a separate managed object context so changes can be ...

NSMutableArray values becoming "invalid"

I m trying to show a database information in a tableview and then the detailed information in a view my problem is as follow: I created a NSMutableArray: NSMutableArray *myArray = [[NSMutableArray ...

iPhone numberpad with decimal point

I am writing an iPhone application which requires the user to enter several values that may contain a decimal point (currency values, percentages etc.). The number of decimal places in the values ...

热门标签