【发布时间】:2014-05-08 22:55:44
【问题描述】:
我有两个UISlider 代表物品的最低和最高价格。我将这些以及其他各种数据传递回之前的控制器。
我使用了一种协议方法并将前一个控制器设置为委托,以便将值传递回控制器。
我可以轻松地从数组中抓取其他对象,因为它们是字符串。我只是使用:
[_finalSelectionForRefinement containsObject:@"size"];
这是我在推送控制器中所做的:
// create dictionary with keys minimum and maximum that hold the
// position of the slider as a float
_dictionaryWithSliderValues =
[[NSDictionary alloc] initWithObjectsAndKeys:[NSNumber numberWithFloat:_minSliderPosition], @"minimum",
[NSNumber numberWithFloat:_maxSliderPosition], @"maximum", nil];
// store this in the array that is retrieved in previous controller
[_finalSelectionForRefinement addObject:_dictionaryWithSliderValues];
我的问题是我现在如何使用最小和最大键来抓取滑块位置浮动对象?
以为我可以使用 NSPredicate,但我在博客和 YouTube 上遇到的示例对我的特定需求没有帮助。
希望能得到一些帮助
问候
更新 - 前一个控制器中我需要检索滑块最小值和最大值的方法的简短片段:
-(PFQuery *)queryForCollection
{
PFQuery *query = [PFQuery queryWithClassName:@"Garments"];
if (_selectedRowInFilterPicker == 0) {
NSLog(@"ORDER BY RECOMMENDED");
[query orderByDescending:@"recommended"];
} else if (_selectedRowInFilterPicker == 1) {
NSLog(@"ORDER BY NEWEST ITEMS");
[query orderByDescending:@"createdAt"];
} else if (_selectedRowInFilterPicker == 2) {
NSLog(@"ORDER BY DESCENDING USING PRICE");
[query orderByDescending:@"price"];
} else if (_selectedRowInFilterPicker == 3) {
NSLog(@"ORDER BY ASCENDING USING PRICE");
[query orderByAscending:@"price"];
}
if ([_selectionFromRefineResultsController count] > 0) {
NSLog(@"Selection FROM REF MADE");
// Gender
if ([_selectionFromRefineResultsController containsObject:@"Male"]) {
[query whereKey:@"gender" equalTo:@1];
}
if ([_selectionFromRefineResultsController containsObject:@"Female"]) {
[query whereKey:@"gender" equalTo:@2];
}
}
// Here I need to check there is a minimum or maximum value in the array
// If there is I can user [query whereKey:@"price" greaterThan:MINVAL] and MAXVAL
// This will return items within the correct price range.
这个 queryForCollection 方法是从另一个名为 performQuery 的方法中调用的,该方法在第二个控制器的按钮被点击以将数据传递回首先推送它的控制器时调用。
【问题讨论】:
-
在需要使用这些值的地方发布您的代码。除了实际进行过滤的细节之外,您应该进行所有设置。
-
有什么理由不能将 _finalSelectionForRefinement 设为字典吗? _finalSelectionForRefinement 中除了 _dictionaryWithSliderValues 之外还有其他字典吗?
-
@rmaddy 该代码将毫无用处,因为它只是一个对我的数组进行多次调用的方法,例如[_finalSelectionForRefinement containsObject:@"colour"];, [_finalSelectionForRefinement containsObject:@"size"];等等。因为我正在使用的这个特定对象不是字符串,所以我无法通过这种方式搜索它。
-
Ethan 我没有将 _finalSelectionForRefinement 设为 NSDictionary,因为我存储在其中的 90% 的对象都是可以用来识别每个对象的字符串。使用 NSMutableArray 更有意义。字典会起作用,但不会。嗯,这将是最后的手段,因为我必须重构一大堆代码。
-
@LondonGuy 我不确定我是否理解你在做什么......如果你没有与该字符串关联的其他值,检查数组是否包含 @"size" 有什么好处?
标签: objective-c cocoa-touch nsmutablearray nsdictionary nspredicate