1

I am using ELCImagePickerController library because I want to select Multiple Image from gallery, and if user select few images and come out from the gallery and if they again go to the gallery, the selected image should show in that collection view, could some one help me how to do this.

Larme
  • 24,190
  • 6
  • 51
  • 81
VyTcdc
  • 986
  • 10
  • 32
  • And what have you tried? – Larme Aug 08 '16 at 09:38
  • I have checked ElcassetTablePickker.m this page, and checked setSelected, ELCAssetCell, setAssets these all methods but not able to understand how to do. – VyTcdc Aug 08 '16 at 09:40
  • Your question is either unclear either too broad. There is a sample: https://github.com/B-Sides/ELCImagePickerController/tree/master/Classes and I don't even know if you understand the delegate pattern, and if you are able to do what understand how works UIImagePickerViewController (which limits indeed for one asset selected, but `ELCImagePickerController` should be using the same logic). – Larme Aug 08 '16 at 09:44
  • Actually My requirement is whatever Image I selected in the Imagegallery and if I return back to app and again If i go to the same gallery, I want to show the previous selected tick mark(Images). – VyTcdc Aug 08 '16 at 09:48
  • Now you got my question? Now are you Clear? – VyTcdc Aug 08 '16 at 09:49
  • use Global array.Once you get the objects into array it won't change until you are not adding other objects again or else you can save array to NSUserDefault. – user3182143 Aug 08 '16 at 09:54
  • Could you explain me through code in which Method I use Global array or nsuserdefault. pls. – VyTcdc Aug 08 '16 at 09:57
  • OK I will give you sample code.But it is for tableView select deselect.Once you select or deselect it saves in NSUserDefault and when run again it shows previous selected or deselected row.If it is ok for you I will post my code. – user3182143 Aug 08 '16 at 10:03
  • It is very simple code you can understand easily.Is it Ok?.You have to customize my code. – user3182143 Aug 08 '16 at 10:05
  • Check my code.It works perfectly. – user3182143 Aug 08 '16 at 10:23

1 Answers1

2

ViewController.h

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController<UITableViewDataSource,UITableViewDelegate>

@property (strong, nonatomic) IBOutlet UITableView *tableViewSelectedPreviousCheckUnCheck;

@end

ViewController.m

#import "ViewController.h"

@interface ViewController ()
{
  NSMutableArray *arrProductSelection,*arrProductSelectDeSelectCheckMark,*arrFetchedresult;
  NSArray *arrayFetchFromDefaults;
}

@end

@implementation ViewController

@synthesize tableViewSelectedPreviousCheckUnCheck;

- (void)viewDidLoad
{
  [super viewDidLoad];
  // Do any additional setup after loading the view from its nib.
  arrProductSelection = [[NSMutableArray alloc]initWithObjects:@"iPhone",@"iPad",@"iPod",@"iTV",@"iWatch",@"iMac",nil];
}
- (void)didReceiveMemoryWarning
{
  [super didReceiveMemoryWarning];
  // Dispose of any resources that can be recreated.
}
-(void)viewWillAppear:(BOOL)animated
{
  NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
  arrayFetchFromDefaults = [userDefaults objectForKey:@"selectedcheckmark"];
  arrProductSelectDeSelectCheckMark = [[NSMutableArray alloc]initWithArray:arrayFetchFromDefaults];
  if(arrProductSelectDeSelectCheckMark.count == 0)
  {
      arrProductSelectDeSelectCheckMark = [[NSMutableArray alloc]init];
     for(int j=0;j<[arrProductSelection count];j++)
     {
        [arrProductSelectDeSelectCheckMark addObject:@"deselected"];
     }
   }
   [tableViewSelectedPreviousCheckUnCheck reloadData];
}

#pragma mark - UITableViewDataSource Methods
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
   return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
   return arrProductSelection.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
   NSString *strCell = @"cell";
   UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:strCell];
   if(cell==nil)
   {
      cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:strCell];
   }
   if([[arrProductSelectDeSelectCheckMark objectAtIndex:indexPath.row] isEqualToString:@"deselected"])
     cell.accessoryType = UITableViewCellAccessoryNone;
   else
     cell.accessoryType = UITableViewCellAccessoryCheckmark;
   cell.textLabel.text = [arrProductSelection objectAtIndex:indexPath.row];
   return cell;
}

#pragma mark - UITableViewDelegate Methods
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
   UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
   @try
   {
      CGPoint touchPoint = [cell convertPoint:CGPointZero toView:tableViewCheckMarkSelectionUpdate];
      NSIndexPath *indexPath = [tableViewCheckMarkSelectionUpdate indexPathForRowAtPoint:touchPoint];
      NSLog(@"%@",arrProductSelectDeSelectCheckMark);
      if([arrProductSelectDeSelectCheckMark count]==0)
      {
        for(int i=0; i<[arrProductSelection count]; i++)
        {
            [arrProductSelectDeSelectCheckMark addObject:@"deselected"];
        }
       }
       if([[arrProductSelectDeSelectCheckMark objectAtIndex:indexPath.row] isEqualToString:@"deselected"])
       {
          cell.accessoryType = UITableViewCellAccessoryCheckmark;
          [arrProductSelectDeSelectCheckMark replaceObjectAtIndex:indexPath.row withObject:@"selected"];
       }
       else
       {
          cell.accessoryType = UITableViewCellAccessoryNone;
          [arrProductSelectDeSelectCheckMark replaceObjectAtIndex:indexPath.row withObject:@"deselected"];
       }

       NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
       [defaults setObject:arrProductSelectDeSelectCheckMark forKey:@"selectedcheckmark"];
       [defaults synchronize];
    }
    @catch (NSException *exception)
    {
       NSLog(@"The exception is-%@",exception);
    }
}
@end
user3182143
  • 9,459
  • 3
  • 32
  • 39
  • i am getting this error while executing ur code : use of undeclare identifire tableViewCheckMarkSelectionUpdate. – VyTcdc Aug 08 '16 at 10:44
  • Create tableView.My tableView name is tableViewCheckMarkSelectionUpdate.Like wise create your tableview ans add delegate,and datasource. – user3182143 Aug 08 '16 at 10:44
  • Then what about this : IBOutlet UITableView *tableViewSelectedPreviousCheckUnCheck; – VyTcdc Aug 08 '16 at 10:46
  • Usually when we create the tableView with XIB or Storyboard it shows @property (strong, nonatomic) IBOutlet UITableView *nameOfThe TableViewHere; – user3182143 Aug 08 '16 at 10:49
  • Ok thanks It is working fine. Will try to do in Elc Library. – VyTcdc Aug 08 '16 at 10:51