我目前有一个搜索页面,它会为Web服务加载结果列表。但是当我返回到搜索页面时,我想要“保存”输入的任何内容(例如,“resto italian”),然后将该条目和以前的条目显示在下面的表视图中,就像下面的图片一样:
[image]
我的计划是使用属性列表序列化-如果不存在列表,则创建名为history.plist的属性列表,并用每个搜索术语填充它,将最近十个显示在上述表视图中。
我尝试过的方法:
任何试图做到这一点的教程链接,对我应该做什么的建议或对我已有内容的改进将不胜感激。
[image]
我的计划是使用属性列表序列化-如果不存在列表,则创建名为history.plist的属性列表,并用每个搜索术语填充它,将最近十个显示在上述表视图中。
我尝试过的方法:
// should create history.plist
- (NSString *)dataFilePath {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentationDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
return [documentsDirectory stringByAppendingString:@"history.plist"];
}
/* This is the action for when 'search' is clicked - calls the method above to create
a new plist if it's not already created.
I then try to display the contents of the of the file in the textfield itself
(for testing purposes) but it's not saving/displaying properly at the moment. */
- (IBAction)saveHistory:(id)sender {
NSString *filePath = [self dataFilePath];
if([[NSFileManager defaultManager] fileExistsAtPath:filePath])
{
NSArray *array = [[NSArray alloc] initWithContentsOfFile:filePath];
for (int i = 0; i < (sizeof(array)); i++) {
UITextField *theField = self.searchHistory;
theField.text = [NSString stringWithFormat:@"%@", array];
}
}
UIApplication *app = [UIApplication sharedApplication];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationWillResignActive:) name:UIApplicationWillResignActiveNotification object:app];
}
任何试图做到这一点的教程链接,对我应该做什么的建议或对我已有内容的改进将不胜感激。