0

配列からのデータを使用してテーブルビューを作成しました。今、テーブルビューのすべての行の詳細が必要です。テーブルビューからレシピを選択すると、その特定のレシピの写真を上にして、そのレシピを準備するためのすべての材料と手順が表示されます。私はこの分野が初めてなので、親切に助けてください。

ここに「ViewController.m」があります

#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController

- (void)viewDidLoad
{
[super viewDidLoad];
RecipeList = [[NSMutableArray alloc]init];
[RecipeList addObject:@"Chicken Kabab"];
[RecipeList addObject:@"Chicken Tikka"];
[RecipeList addObject:@"Chicken 65"];
[RecipeList addObject:@"Chicken Do Pyaza"];
CGRect frame = self.view.frame;
RecipeTable = [[UITableView alloc]initWithFrame:frame style:UITableViewStylePlain];
RecipeTable.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
RecipeTable.backgroundColor = [UIColor cyanColor];
RecipeTable.delegate = self;
RecipeTable.dataSource = self;
[self.view addSubview:RecipeTable];
[RecipeTable setScrollEnabled:YES];
[RecipeTable setUserInteractionEnabled:YES];
[RecipeTable setRowHeight:35];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
return @"RECIPES";
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

return RecipeList.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
if (!cell) {
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
}
cell.textLabel.text = [RecipeList objectAtIndex:indexPath.row];
return cell;

}
@end
4

5 に答える 5

0

次のチュートリアルがu..Segueに役立つことを願っています

于 2013-02-26T10:42:25.453 に答える
0

これを試してください。UITableViewのDidSelectRowデリゲートを使用する必要があります

 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// Navigation logic may go here. Create and push another view controller.

 DetailViewController *detailViewController = [[DetailViewController alloc] initWithNibName:@"DetailViewController" bundle:nil];
NSString *strDishName = [RecipeList objectAtIndex:indexPath.row];
detailViewController.strDishDetail =strDishName;
 // ...
 // Pass the selected object to the new view controller.
 [self.navigationController pushViewController:detailViewController animated:YES];   
}
于 2013-02-26T07:30:55.823 に答える
0

レシピ名をdetailViewControllerに渡すだけです。次に、レシピの名前に応じて、UIImageViewに適切な画像をロードできます。コードのrecipenameは、detailViewControllerのNSStringです。プロパティとして宣言します。

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{   
    DetailViewController *detailViewController = [[DetailViewController alloc] initWithNibName:@"DetailViewController" bundle:nil];
    NSString *name=[recipe objectAtIndex:indexPath.row];
      detailViewController.recipename=name; 
    [self.navigationController pushViewController:detailViewController animated:YES];

}

次に、detaiViewController.mで

    - (void)viewDidLoad
    {
        [super viewDidLoad];
        if([recipename isEqualToString:@"Pizza"])
         {
           UIImage *image = [UIImage imageNamed: @"pizza.png"];
           [img setImage:image];
         }
        else if([recipename isEqualToString:@"Chicken 65"])
         {
           UIImage *image = [UIImage imageNamed: @"chicken.png"];
           [img setImage:image];
         } 
    }
于 2013-02-26T07:21:11.880 に答える
0

プッシュされた別の ViewController に特定の Dish の詳細を入力したい場合、最も簡単な方法は、その特定の Dish に必要なすべての詳細を含むNSObjectを作成し、それを配列として維持することです。tableView で行を選択すると、didSelectRowAtIndexPath:その indexPath でオブジェクトを取得し、プッシュされている次の VC に渡します。詳細 VC では、オブジェクトから詳細を入力できます。

このようにする代わりに

  RecipeList = [[NSMutableArray alloc]init];
 [RecipeList addObject:@"Chicken Kabab"];

のようなことをする

  RecipeList = [[NSMutableArray alloc]init];
 [RecipeList addObject:dishObj];

ここで、dishObj は、料理名、画像、およびレシピを含むクラス Dish の NSObject です。

 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
    }
    Dish *dishObject = [RecipeList objectAtIndex:indexPath.row];
    cell.textLabel.text = dishObject.dishName;
    return cell;
于 2013-02-26T07:08:19.057 に答える
0

UITableView の DidSelectRow デリゲートを使用する必要があります。次に、レシピを選択すると、DidSelectRow デリゲートが呼び出されます。このデリゲート内で、新しい ViewController にプッシュするためのコーディングを行います。新しい ViewController の上に UIImageView を作成し、 TableViewCell から新しい viewController の UIImageView に画像を渡します

于 2013-02-26T06:51:55.420 に答える