标签:
//没有合理的计划让自己处于特别尴尬的境地,从现在开始要有合理的规划,每周的工作内容,每天的工作内容,每天及每周,每月的学习进度都要有一个清晰的计划.
一.block传值的使用.
1.现在有这样一个例子,需要将控制器b输入后的文字,传值到控制A的label上,如何用block实现?
//-----控制器b //.h typedef void (^ReturnText)(NSString *text); //returnText是block的名称,text是传的参数 //定义block @property (nonatomic,copy)ReturnText returnText; //返回block方法 - (void)returnText:(ReturnText) returnText; //.m - (void)returnText:(ReturnText) returnText{ self.returnText = returnText; } - (void)viewWillDisappear:(BOOL)animated{ [super viewWillDisappear:animated]; //设置block值 if (self.returnText ){//不为空,就是控制器A需要调用它,否则此block为空 self.retureText(text); } }
//控制器A调用控制器b block 控制器b *b = [[控制器b alloc] init]; [b returnData:^(NSString *text) { //这段是关键代码,如果不调用它,block为空 self.text = text; }]; [self.navigationController pushViewController:b animated:YES];
二.相机与相册的使用及添加相册逻辑分析
1.1相机与相册的使用
//创建相机,相册 UIImagePickerController *cameraPc = [[UIImagePickerController alloc] init]; cameraPc.delegate = self; cameraPc.sourceType = UIImagePickerControllerSourceTypeCamera; //相机 cameraPc.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; //相册 [self presentViewController:cameraPc animated:YES completion:nil];
1.2代理回调方法
需要导入#import <MobileCoreServices/MobileCoreServices.h>框架,在framwork添加并导入头文件
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info{ [picker dismissViewControllerAnimated:YES completion:nil]; NSString *mediaType = info[UIImagePickerControllerMediaType]; UIImage *tempImg; if ([mediaType isEqualToString:(__bridge NSString *)kUTTypeImage]){ /* Let‘s get the metadata. This is only for images. Not videos */ NSDictionary *metadata = info[UIImagePickerControllerMediaMetadata]; UIImage *theImage = info[UIImagePickerControllerOriginalImage];//原图//界面显示 tempImg = theImage; } [self.imageArray addObject:tempImg]; [self handleShowSelectionAndCameraPhotos]; }
三.键盘返回事件和textView设置placeHolder(隐蔽文字)
//设置隐蔽文字,思路是创建一个label,放在textView上,并设置enable为NO,当文字发生改变时,隐藏label,否则显示. - (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text { //because Done is \n, if ([text isEqualToString:@"\n"]) { [textView resignFirstResponder]; if (!textView.text.length) { self.placeholderL.text = @"请描述您的问题"; }else{ self.placeholderL.text = @""; } return NO; } return YES; }
标签:
原文地址:http://www.cnblogs.com/TheYouth/p/5203459.html