UINavigationController, UITableView
FPProductListViewController.h
#import “FPProductDetailViewController.h”
#import “FPCartViewController.h”
<UITableViewDataSource,UITableViewDelegate>
NSArray *arysampleData;
@property (strong, nonatomic) NSMutableDictionary *dicProductDetailFrmProdctLst;
@property (strong, nonatomic) NSMutableArray *arySelectedProductsFrmPrdctLst;
@property (strong, nonatomic) NSArray *aryTableData;
@property (strong, nonatomic) IBOutlet UITableView *tblVwProductList;
FPProductListViewController.m
– (void)viewDidLoad {
[super viewDidLoad];
float width;
float height;
width = [[UIScreen mainScreen] bounds].size.width;
height = [[UIScreen mainScreen] bounds].size.height;
UIImage *backGroundImage = [self imageWithImage:[UIImage imageNamed:@”BackGround_For_All”] scaledToSize:CGSizeMake(width, height)];
self.view.backgroundColor = [UIColor colorWithPatternImage:backGroundImage];
arysampleData = @[ @{ @”description”: @”2016-06-14″,
@”Blocks”: @[ @{ @”title”: @”Block A1″,@”image”:@”0.png” },
@{ @”title”: @”Block A2″,@”image”:@”1.png” },
@{ @”title”: @”Block A3″,@”image”:@”3.png” },
@{ @”title”: @”Block A4″,@”image”:@”4.png” },
@{ @”title”: @”Block A5″,@”image”:@”5.png” },
@{ @”title”: @”Block A6″,@”image”:@”6.png” },
@{ @”title”: @”Block A7″,@”image”:@”7.png” },
@{ @”title”: @”Block A8″,@”image”:@”8.png” },
@{ @”title”: @”Block A9″,@”image”:@”9.png” },
@{ @”title”: @”Block A10″,@”image”:@”10.png” }
]
},
@{ @”description”: @”2016-06-21″,
@”Blocks”: @[ @{ @”title”: @”Block B1″,@”image”:@”11.png” },
@{ @”title”: @”Block B2″,@”image”:@”12.png” },
@{ @”title”: @”Block B3″,@”image”:@”13.png” },
@{ @”title”: @”Block B4″,@”image”:@”14.png” },
@{ @”title”: @”Block B5″,@”image”:@”15.png” }
]
},
@{ @”description”: @”2015-09-30″,
@”Blocks”: @[ @{ @”title”: @”Block C1″,@”image”:@”0.png” },
@{ @”title”: @”Block C2″,@”image”:@”2.png” },
@{ @”title”: @”Block C3″,@”image”:@”4.png” },
@{ @”title”: @”Block C4″,@”image”:@”6.png” },
@{ @”title”: @”Block C5″,@”image”:@”8.png” }
]
},
];
// NSSortDescriptor *discriptor = [[NSSortDescriptor alloc]initWithKey:@”description” ascending:YES];
// NSArray *descriptors = [NSArray arrayWithObject:discriptor];
// self.aryTableData = [arysampleData sortedArrayUsingDescriptors:descriptors];
// NSLog(@”%@”,arysampleData);
self.aryTableData = @[ @{ @”product name”: @”Coverage Products”,
@”product detail”: @[@{@”ProductId”: @”1″,@”image”: @”Productimage1″,@”name”: @”SurgeShield Only”,@”detail”: @”SurgeShield is a whole-house surge protection program administered by FPL Energy Services, Inc”,@”price”:@”9.95″,@”productQuantity”: @”1″},
@{@”ProductId”: @”2″,@”image”: @”Productimage2″,@”name”: @”Electronics Surge Protection Only”,@”detail”: @”surge protector. Most designs serve one immediately obvious function — they let you plug multiple components into one power outlet.”,@”price”:@”9.95″,@”productQuantity”: @”1″},
@{@”ProductId”: @”3″,@”image”: @”Productimage3″,@”name”: @”Surge Protection Bundle”,@”detail”: @” Surge Protector Strip gives you the power you need for your electronic devices.”,@”price”:@”14.95″,@”productQuantity”: @”1″}]
},
];
NSLog(@”%@”,self.aryTableData);
self.arySelectedProductsFrmPrdctLst = [[NSMutableArray alloc]init];
// Do any additional setup after loading the view, typically from a nib.
}
#pragma mark – UITableView
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return [self.aryTableData count];
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [[[self.aryTableData objectAtIndex:section] objectForKey:@”product detail”]count];
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier = @”Cell”;
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
}
UIImageView *imageViewProductImage = (UIImageView *)[cell viewWithTag:100];
imageViewProductImage.image = [UIImage imageNamed:[[[[self.aryTableData objectAtIndex:indexPath.section]objectForKey:@”product detail”]objectAtIndex:indexPath.row]objectForKey:@”image”]];
UILabel *labelProductName = (UILabel *)[cell viewWithTag:101];
labelProductName.text = [[[[self.aryTableData objectAtIndex:indexPath.section]objectForKey:@”product detail”]objectAtIndex:indexPath.row]objectForKey:@”name”];
UILabel *lblProductPrice = (UILabel *)[cell viewWithTag:102];
lblProductPrice.text = [NSString stringWithFormat:@”$%@”,[[[[self.aryTableData objectAtIndex:indexPath.section]objectForKey:@”product detail”]objectAtIndex:indexPath.row]objectForKey:@”price”]];
UIButton *btnAdd = (UIButton *)[cell viewWithTag:103];
btnAdd.tag = indexPath.row;
[btnAdd addTarget:self action:@selector(btnAddClicked:) forControlEvents:UIControlEventTouchUpInside];
return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// self.dicProductDetailFrmProdctLst = [[NSMutableDictionary alloc]init];
// [self.dicProductDetailFrmProdctLst setObject:@”Name” forKey:@”Philippe”];
// [self performSegueWithIdentifier:@”cellToProductDetailViewController” sender:self.dicProductDetailFrmProdctLst];
}
#pragma mark – UITableViewDelegate methods
-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
NSString *header = [[self.aryTableData objectAtIndex:section]objectForKey:@”product name”];
return header;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
return 30.0;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 80;
}
– (IBAction)btnBackClicked:(id)sender
{
[self.navigationController popViewControllerAnimated:YES];
}
– (IBAction)btnCartClicked:(id)sender
{
NSLog(@”%@”,self.arySelectedProductsFrmPrdctLst);
}
– (IBAction)btnAddClicked:(UIButton*)sender
{
NSLog(@”%ld”,sender.tag);
// UITableViewCell *cell = (UITableViewCell *)sender.superview;
// NSIndexPath *indexPath = [self.tblVwRef indexPathForCell:cell];
UITableViewCell *cell = (UITableViewCell *)sender.superview.superview;
NSIndexPath *indexPath = [self.tblVwProductList indexPathForCell:cell];
UIAlertController *anAlertController = [UIAlertController alertControllerWithTitle:@”” message:@”This product has been added to the cart. Do you want to view the cart?” preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *anAlertActionYes = [UIAlertAction actionWithTitle:@”YES” style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
NSLog(@”YES”);
NSLog(@”%@”,self.arySelectedProductsFrmPrdctLst);
[self performSegueWithIdentifier:@”cartBtnToCartViewController” sender:self.arySelectedProductsFrmPrdctLst];
}];
[anAlertController addAction:anAlertActionYes];
UIAlertAction *anAlertActionNo = [UIAlertAction actionWithTitle:@”NO” style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
NSLog(@”NO”);
}];
[anAlertController addAction:anAlertActionNo];
[self presentViewController:anAlertController animated:YES completion:^{
NSLog(@”Completion”);
[self.arySelectedProductsFrmPrdctLst addObject:[[[self.aryTableData objectAtIndex:0]objectForKey:@”product detail”]objectAtIndex:sender.tag]];
}];
}
#pragma mark – Segue
– (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
NSIndexPath *indexPath = [self.tblVwProductList indexPathForSelectedRow];
NSLog(@”%ld”,indexPath.section);
NSLog(@”%ld”,indexPath.row);
if ([segue.identifier isEqualToString:@”cellToProductDetailViewController”])
{
FPProductDetailViewController *prdctDtlVwct = segue.destinationViewController;
prdctDtlVwct.dicProductDetail = [[[self.aryTableData objectAtIndex:indexPath.section]objectForKey:@”product detail”]objectAtIndex:indexPath.row];
//[[self.aryTableData objectAtIndex:indexPath.section]objectForKey:@”product detail”]objectAtIndex:indexPath.row]
}
if ([segue.identifier isEqualToString:@”cartBtnToCartViewController”])
{
NSLog(@”cartBtnToCartViewController”);
if ([self.arySelectedProductsFrmPrdctLst count] > 0)
{
FPCartViewController *crtVwCt = segue.destinationViewController;
crtVwCt.arySelectedProductsFromCart = self.arySelectedProductsFrmPrdctLst;
}
else
{
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:@”Please select atleast one product” preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *alrtActnOk = [UIAlertAction actionWithTitle:@”OK” style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
NSLog(@”OK”);
}];
[alertController addAction:alrtActnOk];
[self presentViewController:alertController animated:YES completion:^{
}];
}
}
}
– (UIImage *)imageWithImage:(UIImage *)image scaledToSize:(CGSize)newSize {
//UIGraphicsBeginImageContext(newSize);
// In next line, pass 0.0 to use the current device’s pixel scaling factor (and thus account for Retina resolution).
// Pass 1.0 to force exact pixel size.
UIGraphicsBeginImageContextWithOptions(newSize, NO, 0.0);
[image drawInRect:CGRectMake(0, 0, newSize.width, newSize.height)];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}
FPCartViewController.h
<UITableViewDataSource,UITableViewDelegate>
int productQuantity;
float price;
float totalPrice;
BOOL isInOrderConfirmationView;
@property (strong, nonatomic) NSMutableArray *arySelectedProductsFromCart;
@property (weak, nonatomic) IBOutlet UITableView *tblVwSelectedProductList;
@property (weak, nonatomic) IBOutlet UIButton *btnBack;
@property (weak, nonatomic) IBOutlet UIButton *btnCheckOut;
@property (weak, nonatomic) IBOutlet UIButton *btnProceed;
@property (weak, nonatomic) IBOutlet UILabel *lblTotalPrice;
– (void)viewDidLoad {
[super viewDidLoad];
float width;
float height;
width = [[UIScreen mainScreen] bounds].size.width;
height = [[UIScreen mainScreen] bounds].size.height;
UIImage *backGroundImage = [self imageWithImage:[UIImage imageNamed:@”BackGround_For_All”] scaledToSize:CGSizeMake(width, height)];
self.view.backgroundColor = [UIColor colorWithPatternImage:backGroundImage];
NSLog(@”%@”,self.arySelectedProductsFromCart);
NSLog(@”%f”,[[[self.arySelectedProductsFromCart valueForKey:@”price”] objectAtIndex:0]floatValue]);
totalPrice = 0;
for (int i = 0; i<self.arySelectedProductsFromCart.count; i++)
{
totalPrice = totalPrice + [[[self.arySelectedProductsFromCart valueForKey:@”price”] objectAtIndex:i]floatValue];
}
NSLog(@”%f”,totalPrice);
self.lblTotalPrice.text = [NSString stringWithFormat:@”$%0.2f”,totalPrice];
// Do any additional setup after loading the view.
}
-(void)viewWillAppear:(BOOL)animated
{
//isInOrderConfirmationView = NO;
if (isInOrderConfirmationView == YES)
{
self.btnCheckOut.hidden = YES;
self.btnProceed.hidden = NO;
self.tblVwSelectedProductList.userInteractionEnabled = NO;
}
else
{
self.btnCheckOut.hidden = NO;
self.btnProceed.hidden = YES;
self.tblVwSelectedProductList.userInteractionEnabled = YES;
}
}
#pragma mark – UITable View Delegates
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [self.arySelectedProductsFromCart count];
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell;
if (isInOrderConfirmationView == NO)
{
static NSString *cellIdentifier = @”CellNew”;
cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil)
{
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
}
UIImageView *imageViewProductImage = (UIImageView *)[cell viewWithTag:100];
UILabel *labelProductName = (UILabel *)[cell viewWithTag:101];
UILabel *lblProductPrice = (UILabel *)[cell viewWithTag:102];
UIButton *btnAdd = (UIButton *)[cell viewWithTag:103];
UILabel *lblProductQuantity = (UILabel *)[cell viewWithTag:104];
UIButton *btnMinus = (UIButton *)[cell viewWithTag:105];
imageViewProductImage.image = [UIImage imageNamed:[[self.arySelectedProductsFromCart objectAtIndex:indexPath.row] objectForKey:@”image”]];
labelProductName.text = [[self.arySelectedProductsFromCart objectAtIndex:indexPath.row] objectForKey:@”name”];
float tempPrice;
tempPrice = [[[self.arySelectedProductsFromCart objectAtIndex:indexPath.row] objectForKey:@”price”] floatValue] * [[[self.arySelectedProductsFromCart objectAtIndex:indexPath.row] objectForKey:@”productQuantity”] intValue];
lblProductPrice.text = [NSString stringWithFormat:@”$%0.2f”,tempPrice];
btnAdd.hidden = NO;
btnAdd.tag = indexPath.row;
[btnAdd addTarget:self action:@selector(btnAddClicked:) forControlEvents:UIControlEventTouchDown];
lblProductQuantity.text = [[self.arySelectedProductsFromCart objectAtIndex:indexPath.row] objectForKey:@”productQuantity”];
btnMinus.hidden = NO;
btnMinus.tag = indexPath.row;
[btnMinus addTarget:self action:@selector(btnMinusClicked:) forControlEvents:UIControlEventTouchDown];
}
else
{
static NSString *cellIdentifier = @”CellForOrderSummary”;
cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil)
{
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
}
UIImageView *imageViewProductImage = (UIImageView *)[cell viewWithTag:106];
UILabel *labelProductName = (UILabel *)[cell viewWithTag:107];
UILabel *lblProductPrice = (UILabel *)[cell viewWithTag:108];
imageViewProductImage.image = [UIImage imageNamed:[[self.arySelectedProductsFromCart objectAtIndex:indexPath.row] objectForKey:@”image”]];
labelProductName.text = [[self.arySelectedProductsFromCart objectAtIndex:indexPath.row] objectForKey:@”name”];
//lblProductPrice.text = [[self.arySelectedProducts objectAtIndex:indexPath.row] objectForKey:@”detail”];
float tempTotalPrice = [[[self.arySelectedProductsFromCart objectAtIndex:indexPath.row] objectForKey:@”price”] floatValue] * [[[self.arySelectedProductsFromCart objectAtIndex:indexPath.row] objectForKey:@”productQuantity”] intValue];
lblProductPrice.text = [NSString stringWithFormat:@”$%0.2f”,tempTotalPrice];
}
return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
}
#pragma mark – UITableViewDelegate methods
-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
NSString *header = @”Selected Products”;
return header;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
return 30.0;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 70.0;
}
– (IBAction)btnBackClicked:(id)sender
{
// [self.arySelectedProductsFromCart removeAllObjects];
if (isInOrderConfirmationView == NO)
{
[self.navigationController popViewControllerAnimated:YES];
}
else
{
isInOrderConfirmationView = NO;
self.btnProceed.hidden = YES;
self.btnCheckOut.hidden = NO;
self.tblVwSelectedProductList.userInteractionEnabled = YES;
[self.tblVwSelectedProductList reloadData];
}
}
– (IBAction)btnCheckOutClicked:(id)sender {
if ([self.arySelectedProductsFromCart count] <= 0 )
{
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:@”Please select atleast one product” preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *alrtActnOk = [UIAlertAction actionWithTitle:@”OK” style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
NSLog(@”OK”);
}];
[alertController addAction:alrtActnOk];
[self presentViewController:alertController animated:YES completion:^{
}];
}
else
{
isInOrderConfirmationView = YES;
self.btnProceed.hidden = NO;
self.btnCheckOut.hidden = YES;
self.tblVwSelectedProductList.userInteractionEnabled = NO;
[self.tblVwSelectedProductList reloadData];
}
}
– (IBAction)btnProceedClicked:(id)sender
{
NSLog(@”%@”,self.arySelectedProductsFromCart);
}
– (IBAction)btnAddClicked:(UIButton *)sender
{
NSLog(@”%ld”,sender.tag);
NSLog(@”%@”,self.arySelectedProductsFromCart);
productQuantity = [[[self.arySelectedProductsFromCart objectAtIndex:sender.tag]objectForKey:@”productQuantity”] intValue];
productQuantity ++;
price = [[[self.arySelectedProductsFromCart objectAtIndex:sender.tag]objectForKey:@”price”] floatValue];
price = price * productQuantity ;
NSMutableDictionary *dicCurrentSelectedProduct = [[NSMutableDictionary alloc]init];
dicCurrentSelectedProduct = [[self.arySelectedProductsFromCart objectAtIndex:sender.tag] mutableCopy];
[dicCurrentSelectedProduct setObject:[NSString stringWithFormat:@”%d”,productQuantity] forKey:@”productQuantity”];
// [dicCurrentSelectedProduct setObject:[NSString stringWithFormat:@”%f”,price] forKey:@”price”];
[self.arySelectedProductsFromCart replaceObjectAtIndex:sender.tag withObject:dicCurrentSelectedProduct];
NSLog(@”%@”,self.arySelectedProductsFromCart);
UITableViewCell *cell;
NSIndexPath *indexPath;
indexPath=[NSIndexPath indexPathForRow:sender.tag inSection:0]; // if section is 0
cell = (UITableViewCell*)[self.tblVwSelectedProductList cellForRowAtIndexPath:indexPath];
UILabel *lblProductQuantity = (UILabel *)[cell viewWithTag:104];
lblProductQuantity.text = [NSString stringWithFormat:@”%d”,productQuantity];
UILabel *lblProductPrice = (UILabel *)[cell viewWithTag:102];
lblProductPrice.text = [NSString stringWithFormat:@”$%0.2f”,price];
totalPrice = totalPrice + [[[self.arySelectedProductsFromCart objectAtIndex:sender.tag]objectForKey:@”price”] floatValue];
self.lblTotalPrice.text = [NSString stringWithFormat:@”$%0.2f”,totalPrice];
}
– (IBAction)btnMinusClicked:(UIButton *)sender
{
NSLog(@”%ld”,sender.tag);
NSLog(@”%@”,self.arySelectedProductsFromCart);
productQuantity = [[[self.arySelectedProductsFromCart objectAtIndex:sender.tag]objectForKey:@”productQuantity”] intValue];
if (productQuantity == 1)
{
UIAlertController *alrtController = [UIAlertController alertControllerWithTitle:nil message:@”Do you want to remove this product from order list?” preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *alrtActnYes = [UIAlertAction actionWithTitle:@”YES” style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
price = [[[self.arySelectedProductsFromCart objectAtIndex:sender.tag]objectForKey:@”price”] floatValue];
totalPrice = totalPrice – price;
if (totalPrice < 0)
{
self.lblTotalPrice.text = @”$0.00″;
}
else
{
self.lblTotalPrice.text = [NSString stringWithFormat:@”$%0.2f”,totalPrice];
}
[self.arySelectedProductsFromCart removeObjectAtIndex:sender.tag];
[self.tblVwSelectedProductList reloadData];
}];
[alrtController addAction:alrtActnYes];
UIAlertAction *alrtActnNo = [UIAlertAction actionWithTitle:@”NO” style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
}];
[alrtController addAction:alrtActnNo];
[self presentViewController:alrtController animated:YES completion:^{
}];
}
else
{
productQuantity –;
price = [[[self.arySelectedProductsFromCart objectAtIndex:sender.tag]objectForKey:@”price”] floatValue];
price = price * productQuantity ;
NSMutableDictionary *dicCurrentSelectedProduct = [[NSMutableDictionary alloc]init];
dicCurrentSelectedProduct = [[self.arySelectedProductsFromCart objectAtIndex:sender.tag] mutableCopy];
[dicCurrentSelectedProduct setObject:[NSString stringWithFormat:@”%d”,productQuantity] forKey:@”productQuantity”];
[self.arySelectedProductsFromCart replaceObjectAtIndex:sender.tag withObject:dicCurrentSelectedProduct];
NSLog(@”%@”,self.arySelectedProductsFromCart);
NSIndexPath *indexPath;
UITableViewCell *cell;
indexPath=[NSIndexPath indexPathForRow:sender.tag inSection:0]; // if section is 0
cell = (UITableViewCell*)[self.tblVwSelectedProductList cellForRowAtIndexPath:indexPath];
UILabel *lblProductQuantity = (UILabel *)[cell viewWithTag:104];
lblProductQuantity.text = [NSString stringWithFormat:@”%d”,productQuantity];
UILabel *lblProductPrice = (UILabel *)[cell viewWithTag:102];
lblProductPrice.text = [NSString stringWithFormat:@”$%0.2f”,price];
totalPrice = totalPrice – [[[self.arySelectedProductsFromCart objectAtIndex:sender.tag]objectForKey:@”price”] floatValue];
self.lblTotalPrice.text = [NSString stringWithFormat:@”$%0.2f”,totalPrice];
}
}
– (UIImage *)imageWithImage:(UIImage *)image scaledToSize:(CGSize)newSize {
//UIGraphicsBeginImageContext(newSize);
// In next line, pass 0.0 to use the current device’s pixel scaling factor (and thus account for Retina resolution).
// Pass 1.0 to force exact pixel size.
UIGraphicsBeginImageContextWithOptions(newSize, NO, 0.0);
[image drawInRect:CGRectMake(0, 0, newSize.width, newSize.height)];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}
FPProductDetailViewController.h
@property (strong,nonatomic) NSMutableDictionary *dicProductDetail;
@property (weak, nonatomic) IBOutlet UIImageView *imgVwProductImage;
@property (weak, nonatomic) IBOutlet UILabel *lblProductInformation;
@property (weak, nonatomic) IBOutlet UILabel *lblProductDetail;
FPProductDetailViewController.m
– (void)viewDidLoad {
[super viewDidLoad];
float width;
float height;
width = [[UIScreen mainScreen] bounds].size.width;
height = [[UIScreen mainScreen] bounds].size.height;
UIImage *backGroundImage = [self imageWithImage:[UIImage imageNamed:@”BackGround_For_All”] scaledToSize:CGSizeMake(width, height)];
self.view.backgroundColor = [UIColor colorWithPatternImage:backGroundImage];
NSLog(@”%@”,self.dicProductDetail);
self.imgVwProductImage.image = [UIImage imageNamed:[self.dicProductDetail objectForKey:@”image”]];
self.lblProductInformation.text = [self.dicProductDetail objectForKey:@”name”];
self.lblProductDetail.text = [self.dicProductDetail objectForKey:@”detail”];
// Do any additional setup after loading the view.
}
– (IBAction)btnActnBack:(id)sender {
[self.navigationController popViewControllerAnimated:YES];
}
– (UIImage *)imageWithImage:(UIImage *)image scaledToSize:(CGSize)newSize {
//UIGraphicsBeginImageContext(newSize);
// In next line, pass 0.0 to use the current device’s pixel scaling factor (and thus account for Retina resolution).
// Pass 1.0 to force exact pixel size.
UIGraphicsBeginImageContextWithOptions(newSize, NO, 0.0);
[image drawInRect:CGRectMake(0, 0, newSize.width, newSize.height)];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}
Click here to download Navigation with Segue OR Data pass in Navigation with Segue Sample Project