iOS uitableview自定义相册(实现拍照并保存在指定目录以相册的形式展示图片)

该博客介绍了如何在iOS应用中使用UITableView创建一个自定义相册,通过叠加两个UIButton实现照片的选择和展示。利用cell的tag属性及代理方法监听用户操作,但目前还缺少图片点击放大展示和图片过多时的快速加载功能。
摘要由CSDN通过智能技术生成

原理:
图片的展示是通过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) {
     
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值