Markus Markus - 5 months ago 28
Objective-C Question

pop-up about recipe select in table view

i need this following helped: i want that when i click on a recipie (so when i check) and after i click on button, i want a pop up that say me name of recipe that i select and price

RECIPEVIEWCONTROLLER.M

#import "RecipeViewController.h"
#import "Recipe.h"

@interface RecipeViewController ()

@end

@implementation RecipeViewController {
NSArray *recipes;
}

- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
// Custom initialization
}
return self;
}

- (void)viewDidLoad
{
[super viewDidLoad];

self.navigationItem.title = @"Recipe Book";
UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStyleBordered target:nil action:nil];
[[self navigationItem] setBackBarButtonItem:backButton];

// Create recipe array
Recipe *recipe1 = [Recipe new];
recipe1.name = @"Mushroom Risotto";
recipe1.detaill = 20;
recipe1.imageFile = @"mushroom_risotto.jpg";

Recipe *recipe2 = [Recipe new];
recipe2.name = @"Egg Benedict";
recipe2.detaill = 30;
recipe2.imageFile = @"egg_benedict.jpg";

Recipe *recipe3 = [Recipe new];
recipe3.name = @"Full Breakfast";
recipe3.detaill = 20;
recipe3.imageFile = @"full_breakfast.jpg";

Recipe *recipe4 = [Recipe new];
recipe4.name = @"Hamburger";
recipe4.detaill = 30;
recipe4.imageFile = @"hamburger.jpg";

Recipe *recipe5 = [Recipe new];
recipe5.name = @"Ham and Egg Sandwich";
recipe5.detaill = 10;
recipe5.imageFile = @"ham_and_egg_sandwich.jpg";



recipes = [NSArray arrayWithObjects:recipe1, recipe2, recipe3, recipe4, recipe5, nil];




// Remove table cell separator
[self.tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];

// Assign our own backgroud for the view
self.parentViewController.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"common_bg"]];
self.tableView.backgroundColor = [UIColor clearColor];

// Add padding to the top of the table view
UIEdgeInsets inset = UIEdgeInsetsMake(5, 0, 0, 0);
self.tableView.contentInset = inset;



}

- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return recipes.count;
}

- (UIImage *)cellBackgroundForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSInteger rowCount = [self tableView:[self tableView] numberOfRowsInSection:0];
NSInteger rowIndex = indexPath.row;
UIImage *background = nil;

if (rowIndex == 0) {
background = [UIImage imageNamed:@"cell_top.png"];
} else if (rowIndex == rowCount - 1) {
background = [UIImage imageNamed:@"cell_bottom.png"];
} else {
background = [UIImage imageNamed:@"cell_middle.png"];
}

return background;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

// Configure the cell...
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}

// Display recipe in the table cell
Recipe *recipe = [recipes objectAtIndex:indexPath.row];
UIImageView *recipeImageView = (UIImageView *)[cell viewWithTag:100];
recipeImageView.image = [UIImage imageNamed:recipe.imageFile];

UILabel *recipeNameLabel = (UILabel *)[cell viewWithTag:101];
recipeNameLabel.text = recipe.name;

UILabel *recipeDetailLabel = (UILabel *)[cell viewWithTag:102];
recipeDetailLabel.tag = recipe.detaill;

// Assign our own background image for the cell
UIImage *background = [self cellBackgroundForRowAtIndexPath:indexPath];

UIImageView *cellBackgroundView = [[UIImageView alloc] initWithImage:background];
cellBackgroundView.image = background;
cell.backgroundView = cellBackgroundView;


return cell;
}

Answer

Try converting value to string, that way IDE won't show error:

recipeDetailLabel.text = [NSString stringWithFormat:@"%d", recipe.detaill];