2015-09-04 by 木易哥哥
实现思路,先定义股票数组字典,一只股票作为1个数组,元素中包含股票数字代码和拼音简称,然后用一个大数组包含所有股票的数组,转成字典。
相关代码如下:
//搜索Text
souSuoText = [[UITextField alloc]initWithFrame:CGRectMake(30, 6, 260,21)];
souSuoText.placeholder = @"请输入股票代码、名称";
souSuoText.font = [UIFont systemFontOfSize:13];
souSuoText.delegate = self;
[souSuoText setReturnKeyType:UIReturnKeyDone];
[souSuoText setKeyboardType:UIKeyboardTypeNumbersAndPunctuation];
souSuoText.clearButtonMode = UITextFieldViewModeWhileEditing;
[souSuoText addTarget:self action:@selector(textFieldChanged) forControlEvents:UIControlEventEditingChanged];//监控件盘值的变化
[souSuoText becomeFirstResponder];
[imageView addSubview:souSuoText];
- (void)textFieldChanged
{
[dataSourceArray removeAllObjects];
NSString *finStr =[[NSString stringWithFormat:@"%@",souSuoText.text]uppercaseString];
NSPredicate *predicate1 = [NSPredicate predicateWithFormat:@"SELF[0] CONTAINS %@",finStr]; //0是代码
NSArray *daArray1 = [ziDianArray filteredArrayUsingPredicate:predicate1];
[dataSourceArray addObjectsFromArray:daArray1];
NSPredicate *predicate2 = [NSPredicate predicateWithFormat:@"SELF[3] CONTAINS %@",finStr]; //3是拼音
NSArray *daArray2 = [ziDianArray filteredArrayUsingPredicate:predicate2];
[dataSourceArray addObjectsFromArray:daArray2];
//NSLog(@"daArray:%@", dataSourceArray);
if ([finStr isEqualToString:@""]) {
[dataSourceArray removeAllObjects];
}
[self loadData];
}