Ios UITableview搜索栏:筛选数组
我在为UITableView使用搜索栏筛选器时遇到问题 我正在多个阵列中记录温度数据:Ios UITableview搜索栏:筛选数组,ios,iphone,uitableview,filtering,uisearchbar,Ios,Iphone,Uitableview,Filtering,Uisearchbar,我在为UITableView使用搜索栏筛选器时遇到问题 我正在多个阵列中记录温度数据: NSMutableArray *timeArray; // Array which saves date and time NSMutableArray *tempInside; // saves inside temp NSMutableArray *tempOutside; // saves outside temp NSMutableArray *timeArraySearch; // Array wh
NSMutableArray *timeArray; // Array which saves date and time
NSMutableArray *tempInside; // saves inside temp
NSMutableArray *tempOutside; // saves outside temp
NSMutableArray *timeArraySearch; // Array which saves date and time searched
NSMutableArray *tempInsideSearch; // saves inside temp searched
NSMutableArray *tempOutsideSearch; // saves outside temp searched
所以要显示所有数据,我有一个UITableView。我将时间数组用于单元格.textlab.text
现在我很难用搜索栏过滤数据。这是我的
filterContentForSearchText
方法:
- (void)filterContentForSearchText:(NSString*)searchText scope:(NSString*)scope
{
NSPredicate *resultPredicate = [NSPredicate
predicateWithFormat:@"SELF contains[cd] %@",
searchText];
tempInsideSearch = [tempInside filteredArrayUsingPredicate:resultPredicate];
tempOutsideSearch = [tempOutside filteredArrayUsingPredicate:resultPredicate];
timeArraySearch = [timeArray filteredArrayUsingPredicate:resultPredicate];
}
我运行了应用程序,得到了一个空数组异常。然后我再次检查了这个方法,发现tempInsideSearch和tempOutsideSearch是空的是正常的,因为它们不包含像“06:41PM”这样的值
最后,我的问题是:
如何过滤临时数组,使其与时间数组的索引相匹配?创建一个具有日期/时间、insideTemp、outsideTemp属性的类,将其实例存储到数组中,并在该数组上应用过滤,而不是使用3个不同的数组来存储高度关联的信息…为什么要使用这么多数组?为什么不使用一个存储所有数据的主数组和一个存储搜索结果的数组?数组中的每个元素都应该是一个有时间的对象或字典,以及两个temp。您好,我不知道如何使用字典。那么,您是指两个数组,例如:
*dataArray,*searchArray
,在这些数组中,我应该将其他数组存储为对象吗?不,不要将其他数组存储在dataArray
中dataArray
应包含一组NSDictionary
(或自定义对象)。每个字典将存储日期/时间、内部温度和外部温度。这将把每组数据作为一个单元保存在一起。你知道在哪里可以找到简单的NSDictionary说明/教程/示例吗?