내 코드가 세트에 요소를 추가하지 않습니다.NSMutableSet 객체를 추가하지 않음
#import <UIKit/UIKit.h>
@interface NHPSearchViewController : UITableViewController
//For using the local DB
@property (strong, nonatomic) NSManagedObjectContext *managedObjectContext;
//texst field where user enters a substance name or a drug name
@property (weak, nonatomic) IBOutlet UITextField *substanceTextField;
//An array for Drug Names, and another array for NHPs
@property (strong, nonatomic) NSMutableSet *drugList;
@property (strong, nonatomic) NSMutableSet *NHPList;
//Contains both drugList and NHP list as one array for the data to be shown for the user.
@property (strong, nonatomic) NSMutableSet *usersList;
@end
내하는 .m 파일 :
@interface NHPSearchViewController()
- (BOOL) checkAndAddToList: (NSString *) substance;
@end
@implementation NHPSearchViewController
@synthesize managedObjectContext;
@synthesize substanceTextField;
@synthesize drugList, NHPList, usersList;
//"Private" helper methods
-(BOOL) checkAndAddToList:(NSString *)substance{
// Set up a predicate for testing if the data exists in the table
NSPredicate *pred = [NSPredicate predicateWithFormat:@"name == %@", substance];
//Run the query to see if the substance is in the Substances Table.
NSMutableArray *results =[NSMutableArray array];
results = [CoreDataHelper searchObjectsForEntity:@"Substances" withPredicate:pred andSortKey:nil andSortAscending:NO andContext:self.managedObjectContext];
if ([results count] > 0){
//Found the substance return YES
Substances *sub = [results objectAtIndex:0];
NSLog(@"Did find a result with name:%@ and class_name as:%@ ",[sub name], [sub class_name]);
//add the name to the appropriate lists.
if([[sub class_name] isEqualToString:@"NHP"]){
NSLog(@"NHP was found adding it to the nhp list");
[NHPList addObject:[sub name]]; //THIS is not working
NSLog(@"NHP count after adding %i", [NHPList count]);
}else if ([[sub class_name] isEqualToString:@"Drugs"]){
NSLog(@"Drug was found adding it to the drug list");
[drugList addObject:[sub name]]; //THIS is also not working
}
//add the name to our list in the view
[usersList addObject:[sub name]]; //This is also not working
return YES;
}else{
//
return YES;
}
return NO;
}
로그 출력 :
[4187 : FB03] 테스트 substanceTextField 값 : 오메가 다음
내 헤더 파일은 3-6-9 [4187 : fb03] 이름이 Omega 3-6-9이고 class_name이 다음과 같은 결과를 찾았습니까? NHP [4187 : fb03 FB03] NHP 목록 : 0 [4187을 추가 한 후 FB03] NHP 수 : NHP는 NHP 목록에 추가 [4187 발견되었다] 0 DrugList : 0 UserList에 : 0
시도 :'[self.NHPList addObject : 이것은 당신이 데이터를 설정할 수있는 유일한 장소 인 경우
, 당신은 또한 단지이 줄을 바꿀 수 [하위 이름]];'또한 self.NHPList가 0이 아닌지 확인하십시오. – lnafziger
그게 작동하지 않았다 – user597608
내 의견의 두 번째 부분을 확인 했습니까? NHplist는 무효입니까? (이것은 @bandejapaisa가 요구하는 것과 같은 질문입니다.) – lnafziger