添加联系人界面

来源:互联网 发布:陪我聊天软件 编辑:程序博客网 时间:2024/04/30 11:02
#import "FYZAddAddressPersonController.h"#import "AddAddressPersonView.h"#import "DXAlertView.h"#import "FYZPhotoLibraryController.h"#import "FYZAddressBookNavigationController.h"@interface FYZAddAddressPersonController ()<UIScrollViewDelegate, FYZPhotoLibraryControllerDelegate>{    BOOL _isSave; //标识用户是否保存}@property (nonatomic, copy) NSString *imageName;//存储点击的图片名字@end@implementation FYZAddAddressPersonController- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];    if (self) {        // Custom initialization        _isSave = NO;    }    return self;}- (void)loadView{    AddAddressPersonView *addView = [[AddAddressPersonView alloc] initWithFrame:[UIScreen mainScreen].bounds];    addView.delegate = self;    self.view = addView;    //为头像添加轻拍手势    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)];    [addView.avatarView addGestureRecognizer:tap];    RELEASE_SAFE(tap);    RELEASE_SAFE(addView);}- (void)scrollViewDidScroll:(UIScrollView *)scrollView{    if (0 != scrollView.frame.origin.y) {        [(AddAddressPersonView *)scrollView resignKeyboard];        [UIView animateWithDuration:0.25 animations:^{            scrollView.frame = [UIScreen mainScreen].bounds;        }];    }}- (void)viewDidLoad{    [super viewDidLoad];    // Do any additional setup after loading the view.    self.view.backgroundColor = [UIColor lightWhiteColor];    [self customizeNavigationBarContent];}- (void)customizeNavigationBarContent{    //titleView    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, 40)];    titleLabel.text = @"添加联系人";    titleLabel.textColor = [UIColor whiteColor];    titleLabel.textAlignment = NSTextAlignmentCenter;    self.navigationItem.titleView = titleLabel;    RELEASE_SAFE(titleLabel);    //leftItem    UIBarButtonItem *leftItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"clsose"] style:UIBarButtonItemStylePlain target:self action:@selector(handleBack:)];    self.navigationItem.leftBarButtonItem = leftItem;    RELEASE_SAFE(leftItem);    //rightItem    UIBarButtonItem *rightItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"doneR"] style:UIBarButtonItemStylePlain target:self action:@selector(handleSave:)];    self.navigationItem.rightBarButtonItem = rightItem;    RELEASE_SAFE(rightItem);}#pragma mark - handleTap- (void)handleTap:(UIGestureRecognizer *)tap{    //模态出图库界面    FYZPhotoLibraryController *photoVC = [[FYZPhotoLibraryController alloc] initWithStyle:UITableViewStylePlain];    //设置代理    photoVC.delegate = self;    FYZAddressBookNavigationController *navigationVC = [[FYZAddressBookNavigationController alloc] initWithRootViewController:photoVC];    [self presentViewController:navigationVC animated:YES completion:nil];    RELEASE_SAFE(photoVC);    RELEASE_SAFE(navigationVC);}#pragma mark - handle Action- (void)handleBack:(UIBarButtonItem *)item{    [(AddAddressPersonView *)self.view resignKeyboard];    [UIView animateWithDuration:0.25 animations:^{        self.view.frame = [UIScreen mainScreen].bounds;    }];    //判断用户是否保存,如果用户没有保存,警告用户是否保存.    if (!_isSave) {        //没有保存警告用户是否保存        DXAlertView *alert = [[DXAlertView alloc] initWithTitle:@"危险" contentText:@"您还没有保存,确定返回?" leftButtonTitle:@"取消" rightButtonTitle:@"确定"];        [alert show];        //__block 防止block对视图控制器对象retain.        __block FYZAddAddressPersonController *vc = self;        alert.rightBlock = ^() {            [vc dismissViewControllerAnimated:YES completion:nil];        };        RELEASE_SAFE(alert);        return;    }}- (void)handleSave:(UIBarButtonItem *)item{    _isSave = YES; //已经保存        //创建person对象来接收self.view传过来的要添加的对象    AddressPerson *person = [(AddAddressPersonView *)self.view addAddressonPerson];        //给封装好的对象添加图片名    //person.imageName = self.imageName;    if (!self.imageName) {        person.imageName = @"grassGreen_avatarEmpty@2x";    } else {        person.imageName = self.imageName;    }        if (![person.name isEqualToString:@""] && ![person.phoneNumber isEqualToString:@""]) {                //修改数据源(让通讯录列表界面添加)        [FYZAddressBookHelper addAddresPerson:person];    }    [self dismissViewControllerAnimated:YES completion:nil];}#pragma mark - UIAlertViewDelegate- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{    switch (buttonIndex) {        case 1:            //如果点击确定,直接返回上一界面            [self dismissViewControllerAnimated:YES completion:nil];            break;        default:            break;    }}#pragma mark - system- (void)didReceiveMemoryWarning{    [super didReceiveMemoryWarning];    // Dispose of any resources that can be recreated.}#pragma mark - FYZPhotoLibraryControllerDelegate- (void)didSelectPhotoWithPhotoName:(NSString *)photoName{    //保存点击的图片名字    self.imageName = photoName;        //将头像换成更改之后的图片    AddAddressPersonView *view = (AddAddressPersonView *)self.view;    view.avatarView.image = [UIImage imageNamed:photoName];}- (void)dealloc{    RELEASE_SAFE(_imageName);    [super dealloc];}@end

0 0
原创粉丝点击