本地保存搜索记录的简单实现
作者:
DDY | 来源:发表于
2017-01-24 10:46 被阅读40次
SearchHistory.png
- (void)loadHistory
{
self.historyArray = [NSMutableArray arrayWithArray:[[NSUserDefaults standardUserDefaults] arrayForKey:@"searchHistoryArray"]];
[self .tableView reloadData];
}
- (void)saveHistory
{
// 防止重复数据
if (![self.historyArray containsObject:_searchField.text]) {
[self.historyArray insertObject:_searchField.text atIndex:0];
// 保存10条
if(self.historyArray.count > 10) {
[self.historyArray removeLastObject];
}
[[NSUserDefaults standardUserDefaults] setObject:self.historyArray forKey:@"searchHistoryArray"];
}
}
本文标题:本地保存搜索记录的简单实现
本文链接:https://www.haomeiwen.com/subject/jpszbttx.html
网友评论