我有一个地址簿类,在这个类中我有一个searchName
方法,现在我想添加一个removeName
从地址簿中删除名称的方法(当我写它时,我认为它很清楚......只是分享)。
无论如何,我虽然是使用preformSelector:@selector(searchNames)
但我在这一行得到错误..这是我的代码:
//method to search address cards
-(NSMutableArray *) searchName:(NSString *) someName{
NSMutableArray *namsFound = [[NSMutableArray alloc] init];
for (AddressCards *addressCard in book){
if ([addressCard.name rangeOfString:someName options:NSCaseInsensitiveSearch].location != NSNotFound)
[namsFound addObject:addressCard];
else if ([addressCard.email rangeOfString:someName options:NSCaseInsensitiveSearch].location != NSNotFound)
[namsFound addObject:addressCard];
else if ([addressCard.country rangeOfString:someName options:NSCaseInsensitiveSearch].location != NSNotFound)
[namsFound addObject:addressCard];
else if ([addressCard.workPlace rangeOfString:someName options:NSCaseInsensitiveSearch].location != NSNotFound)
[namsFound addObject:addressCard];
}
return [namsFound count]? namsFound : nil;
}
我必须使用这个返回的方法声明BOOL
:
-(BOOL) removeName:(NSString *)theName{
if ([theName performSelector:@selector(searchName:)] > 0){
for (AddressCards *card in book)
[book removeObject:theName];
return YES;
}
else
return NO;
}
这就是我试图在 main.m 中测试它的方式:
AdressBook *myBook = [[AdressBook alloc] initWithName:@"Family Address Book"];
if([myBook removeName:@"nir"] == YES)
[myBook list];
else
NSLog(@"Not in address book");
我在这一行得到线程 1 SIGBRT:for (AddressCards *card in book)
请帮我解决这个问题。干杯