【发布时间】:2016-08-19 06:57:06
【问题描述】:
我从nsmutablearray 加载了我的uitableview 数据,但我也想过滤。数据正在完美加载,但现在我需要对其应用过滤功能并重新加载表。到目前为止,这是我为过滤而编写的代码,但它不起作用
NSPredicate *sPredicate;
for (int i=0; i<TableArray.count; i++) {
float hotelDistanceFloat = [[[TableArray objectAtIndex:i]xmlhotel_distance] floatValue];
NSInteger hotelPrice = [[[TableArray objectAtIndex:i]xmlhotel_price] integerValue];
sPredicate = [NSPredicate predicateWithFormat:@"(%ld <= %d AND %f <= %d)" , (long)hotelPrice, numberOfBudget, hotelDistanceFloat,numberOfDistance];
TableArray = [[TableArray filteredArrayUsingPredicate:sPredicate] mutableCopy];
}
numberOfBudget 和 numberOfDistance 是从 uislider 获取的简单 int 值。 TableArray 是我的 mutablearray,其中包含所有 tabledata。
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return TableArray.count;
}
这些是我的 nsmutablearray 包含的值
NSLog(@"Name : %@",[[TableArray objectAtIndex:1]xmlhotel_name]);
NSLog(@"City : %@",[[TableArray objectAtIndex:1]xmlhotel_city]);
NSLog(@"Price : %@",[TableArray objectAtIndex:1]xmlhotel_price);
NSLog(@"Distance : %@",[TableArray objectAtIndex:1]xmlhotel_distance);
NSLog(@"Image : %@",[[TableArray objectAtIndex:1]xmlhotel_image]);
NSLog(@"Stars : %@",[[TableArray objectAtIndex:1]xmlhotel_stars]);
所有这些值都是字符串
【问题讨论】:
-
你没有正确预测,数组数据没有caparison?
-
hotelDistanceFloat 和 hotelPrice 是来自数组的数组值!对不起,我没明白,请你再解释一下。
-
你能显示包含你的数组的值吗?
-
请检查更新的问题
-
你的对象 [TableArray objectAtIndex:1] 是 NSDictionary 吗?
标签: ios objective-c iphone uitableview nspredicate