<code>-(
void
)viewWillAppear:(
BOOL
)animated
{
[super viewWillAppear:animated];
[self readNSUserDefaults];
}
-(
void
)textFieldDidBeginEditing:(UITextField *)textField
{
DLog(@
"开始搜索"
);
self.tableView.hidden = NO;
}
-(IBAction)go:(UITextField *)sender {
DLog(@
"点击go"
);
if
(self.textField.text.length == 0) {
[MyUtil showTipText:@
"搜索内容不能为空"
];
return
;
}
[self SearchText:self.textField.text];
GYSearchDetailedViewController * searchDetailed = getViewController(@
"searchDetailed"
, @
"FindDoctor"
);
searchDetailed.searchInfo = self.textField.text;
[self.navigationController pushViewController:searchDetailed animated:YES];
}
-(
void
)SearchText:(NSString *)seaTxt
{
NSMutableArray *searTXT = [[NSMutableArray alloc] init];
if
(self.historyArray) {
searTXT = [self.historyArray mutableCopy];
}
[searTXT addObject:seaTxt];
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
[userDefaults setObject:searTXT forKey:@
"searchHistory"
];
}
-(
void
)readNSUserDefaults
{
NSUserDefaults *userDefaultes = [NSUserDefaults standardUserDefaults];
self.historyArray = [userDefaultes arrayForKey:@
"searchHistory"
];
[self.tableView reloadData];
}
</code>