0

iOS アプリケーションの開発方法を学んでいますが、助けが必要な問題があります。

次のコードを使用して、解析中のクラスからデータを取得します。

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:  (NSInteger)section
{
return [recipes count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *simpleTableIdentifier = @"RecipeCell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];

if (cell == nil) {
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
}

Recipe *recipe = [recipes objectAtIndex:indexPath.row];

UIImageView *imageView = (UIImageView*) [cell viewWithTag:100];
imageView.image = [UIImage imageNamed:recipe.imageFile];
UILabel *nameLabel = (UILabel*) [cell viewWithTag:101];
nameLabel.text = recipe.name;
UILabel *prepTimeLabel = (UILabel*) [cell viewWithTag:102];
prepTimeLabel.text = recipe.prepTime;

return cell;

}

私のテーブルには、レシピの準備に必要な時間の数値である準備時間の値が保持されています。ユーザーが準備時間に基づいてレシピを表示できるようにしたい. ユーザーが準備する最も速い食事を見ることができるボタンがあるとしましょう。if ステートメントと while ループを試してみましたが、あまり成功しませんでした。if (prepTime stringValue isEqualToString:@"30 mins"] などを試してから残りを実行しましたが、うまくいきませんでした。

どんな助けでも大歓迎です。私が言ったように、私はただ学んでいるので、あなたの説明を新しくするようにしてください.

ありがとうございました

4

1 に答える 1

0

を使用PFQueryTableViewControllerすると、テーブル ビューのデータを取得するために使用する Parse クエリを指定できます。この場合、に基づいてレシピをフィルタリングできますprepTime

ビュー コントローラーで、次のようなものを実装します。

- (PFQuery *)queryForTable
{
  PFQuery *query = [PFQuery queryWithClassName:@"yourRecipeClassName"];
  [query whereKey:@"prepTime" lessThan:self.maxPrepTime];
  /*
    Customise as needed, e.g., could be:
    [query whereKey:@"prepTime" equalTo:@30];
  */
  return query;
}

ビュー コントローラーにプロパティを追加して、現在選択されている prepTime (例@property NSNumber *maxPrepTime) を保持し、選択したフィルターを変更するには、次のようにします。

self.maxPrepTime = @60;
[self.tableView reloadData];

tableView:cellForRowAtIndexPath:メソッド内で追加の作業を行う必要はありません。

于 2013-08-20T01:53:22.207 に答える