갤러리에서 여러 이미지를 선택하고 갤러리에서 몇 개의 이미지를 선택하고 갤러리에서 나오기 때문에 ELCImagePickerController 라이브러리를 사용하고 있습니다. 선택한 이미지가 콜렉션 뷰에 표시되어야합니다. 어떤 사람이이 작업을 수행하는 방법을 알려줄 수 있습니다.ELCImagePickerController를 추가하고 선택한 이미지를 남겨 둡니다.
답변
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
ur 코드를 실행하는 동안이 오류가 발생합니다. 즉, 식별 할 수없는 식별자 tableViewCheckMarkSelectionUpdate를 사용합니다. – VyTcdc
create tableView.My tableView 이름은 tableViewCheckMarkSelectionUpdate입니다. 현명한 테이블 뷰를 만들려면 ans delegate 및 datasource를 추가하십시오. – user3182143
그러면 이것에 대해 : IBOutlet UITableView * tableViewSelectedPreviousCheckUnCheck; – VyTcdc
그리고 당신은 무엇을 시도? – Larme
이 페이지에서 ElcassetTablePickker.m을 확인하고 setSelected, ELCAssetCell, setAssets를 모두 검사했지만 수행 방법을 알 수는 없습니다. – VyTcdc
귀하의 질문이 너무 광범위하게 불분명합니다. 샘플이 있습니다 : https://github.com/B-Sides/ELCImagePickerController/tree/master/Classes 그리고 심지어 당신이 대리자 패턴을 이해하고, 어떻게 작동하는지 이해할 수 있다면 UIImagePickerViewController (실제로 선택된 하나의 자산에 대한 제한이 있지만,'ELCImagePickerController'는 동일한 로직을 사용해야합니다). – Larme