原理:
图片的展示是通过uitableview实现。照片的展示以及选择(uitableviewce’l’l)是通过俩个uibutton的叠加完成。通过设置每个uibutton的tag,并在viewcontroller中实现cell的delegate来实现对uibutton的监听。
.h文件
#import <UIKit/UIKit.h>
#import "PhotoObject.h"
#import "Comm.h"
#import "PhotoTableViewCell.h"
#import "MBProgressHUD.h"
@protocol PhotoViewControllerDelegate <NSObject>
-(void)passSelectPhoto :(NSMutableArray *) array;
@end
@interface PhotoViewController : UIViewController<UIImagePickerControllerDelegate,UINavigationControllerDelegate,UITableViewDelegate,UITableViewDataSource,PhotoTableViewCellDelegate>
{
NSFileManager *fileMgr;
NSMutableArray *photoArray;
NSString * photoSavePath;
NSString * photoFileName;
MBProgressHUD *HUD;
NSMutableArray *passmutableArray;
NSString *datafiloderpath;
}
@property (strong, nonatomic) IBOutlet UITableView *photoTableView;
@property (strong, nonatomic) IBOutlet UIView *backBtn;
@property (strong, nonatomic) IBOutlet UIButton *tackPhotoBtn;
@property (strong, nonatomic) IBOutlet UIButton *cancelBtn;
@property (strong, nonatomic) IBOutlet UIButton *finishBtn;
@property (strong, nonatomic) id <PhotoViewControllerDelegate> delegate;
.m文件
#import "PhotoViewController.h"
#import "AppDelegate.h"
@interface PhotoViewController ()
@end
@implementation PhotoViewController
@synthesize photoTableView;
@synthesize finishBtn;
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
[AppDelegate storyBoradAutoLay:self.view];
fileMgr = [NSFileManager defaultManager];
photoArray=[[NSMutableArray alloc]init];
passmutableArray=[[NSMutableArray alloc] init];
HUD = [[MBProgressHUD alloc] initWithFrame:CGRectMake(self.view.frame.size.width/2, self.view.frame.size.height/2, 300, 100)];
[self.view addSubview:HUD];
//如果设置此属性则当前的view置于后台
// HUD.dimBackground = YES;
//设置对话框文字
HUD.labelText = @"获取照片数据中";
//显示对话框
[HUD showAnimated:YES whileExecutingBlock:^{
//对话框显示时需要执行的操作
//指向文件目录
NSDate * date=[NSDate date];
NSDateFormatter *dateformatter=[[NSDateFormatter alloc] init];
[dateformatter setDateFormat:@"YYYY-MM-dd"];
NSString *datefloder= [dateformatter stringFromDate:date];
datafiloderpath=[NSString stringWithFormat:@"%@/",datefloder];
NSString *documentsDirectory= [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
photoSavePath=[NSString stringWithFormat:@"%@/%@%@", documentsDirectory,photoPath,datafiloderpath];
if (![fileMgr fileExistsAtPath:photoSavePath])
{
[fileMgr createDirectoryAtPath:photoSavePath withIntermediateDirectories:YES attributes:nil error:nil];
}
photoArray=[self getFilenamelistOfType:@"png" fromDirPath:photoSavePath];
photoTableView.delegate=self;
photoTableView.dataSource=self;
sleep(5);
} completionBlock:^{
//操作执行完后取消对话框
//[photoTableView reloadData];
[HUD removeFromSuperview];
}];
}
-(void)viewDidUnload
{
}
-(void)viewDidLayoutSubviews
{
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)btnControll:(UIButton *)sender {
switch (sender.tag) {