#pragma mark 每天总结学习两小时  效率 和 每天学习 研究底层 多进去看看 

// ..........................................................................................//

//                           _ooOoo_                                                        //

//                          o8888888o                                                      //

//                            88" . "88                                                          //

//                              (| -_- |)                                                         // 

//                            O\ = /O                                                         //

//                        ____/`---'\____                                                  //

//                      .   ' \\| |// `.                                                        //

//                       / \\||| : |||// \                                                //  

//                     / _||||| -:- |||||- \                                             //

//                       | | \\\ - /// | |                                                  //

//                     | \_| ''\---/'' | |                                                    //

//                      \ .-\__ `-` ___/-. /                                               //  

//                   ___`. .' /--.--\ `. . __                                                //

//                ."" '< `.___\_<|>_/___.' >'"".                                     //

//               | | : `- \`.;`\ _ /`;.`/ - ` : | |                                      //

//                 \ \ `-. \_ __\ /__ _/ .-` / /                                      //

//         ======`-.____`-.___\_____/___.-`____.-'======     //

//                            `=---='                                                             //

//                                                                                                    //

//..........................................................................................//

//                              道家张三丰                                                  //

 

http://life.httpcn.com/mobile.asp#main

 

http://blog.csdn.net/qq_30513483/article/details/50913120       多种常用封装

NSLog(@"%@",NSStringFromCGRect(self.tableView.frame));  打印frame  

 

#pragma mark     录音播放完成 的代理方法 

- (void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)player successfully:(BOOL)flag {

<!--<添加调用的方法>-->

_playBtn.tag = 0;

[_playBtn setImage:[UIImage imageNamed:@"kai1"] forState:UIControlStateNormal];

 

}

 

#pragma mark 加载广告 的一些问题 AFN 异步下载 但请求是个block  所以要把下载线程放在 同一个网络进程里  否则获取不到 广告的URL  因为下载是异步  ,所以要把异步放在block 内

 

//这一步是获取上次网络请求下来的图片,如果存在就展示该图片,如果不存在就展示本地保存的名为test的图片

NSMutableData * data = [[NSUserDefaults standardUserDefaults]objectForKey:@"imageu"];

if (data.length>0) {

_Imageview.image = [UIImage imageWithData:data];

}else{

 

_Imageview.image = [UIImage imageNamed:@"028"];

}

 

//下面这段代码,是调用AFN下载文件的方法,异步

NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];

AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:configuration];

// 请求是个block  所以要把下载线程放在 同一个网络进程里  否则获取不到 广告的URL  因为下载是异步

AVQuery* query = [AVQuery queryWithClassName:@"ADguanggao"];

[query orderByAscending:@"order"];

[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {

if (error==NULL && objects!= NULL && objects.count > 0) {

AVFile *file = [objects[0] objectForKey:@"AD"];

self.ADURL = file.url?file.url:@"";

NSLog(@"广告的url%@",self.ADURL);

// 图片赋值

//            [self.Imageview sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@",self.ADURL]] placeholderImage:[UIImage imageNamed:@"01"]];

 

NSURL *URL = [NSURL URLWithString:[NSString stringWithFormat:@"%@",self.ADURL]];

NSLog(@"加载下载的%@",URL);

NSURLRequest *request = [NSURLRequest requestWithURL:URL];

NSURLSessionDownloadTask *downloadTask = [manager downloadTaskWithRequest:request progress:nil destination:^NSURL *(NSURL *targetPath, NSURLResponse *response) {

 

NSURL *documentsDirectoryURL = [[NSFileManager defaultManager] URLForDirectory:NSDocumentDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:NO error:nil];

return [documentsDirectoryURL URLByAppendingPathComponent:[response suggestedFilename]];

} completionHandler:^(NSURLResponse *response, NSURL *filePath, NSError *error) {

NSLog(@"File downloaded to: %@", filePath);

 

NSData * image = [NSData dataWithContentsOfURL:filePath];

[[NSUserDefaults standardUserDefaults]setObject:image forKey:@"imageu"];

 

 

}];

[downloadTask resume];

 

}

}];

 

 

 

#pragma mark  设置tableBar 的字体   字体大小 颜色 背景图片 

 

self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:0 green:0.2 blue:0.4 alpha:1];

NSDictionary *dic = @{NSFontAttributeName:[UIFont boldSystemFontOfSize:18.f], NSForegroundColorAttributeName:[UIColor blackColor]};

self.navigationController.navigationBar.titleTextAttributes = dic;

 

#define APP_FONT @"YouYuan"   下载字体 YouYuan.TTF  

_title.font = [UIFont fontWithName:APP_FONT size:15];

_title.textColor = [UIColor colorWithHexString:@"#171717"];

 

#pragma mark  广告页 下载缓存 实现   和   简约引导页的加载 

_Imageview= [[UIImageView  alloc]initWithFrame:[UIScreen mainScreen].bounds];

_Imageview.userInteractionEnabled = YES;

UITapGestureRecognizer *singleTap =[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(UesrClicked)];

 

[_Imageview addGestureRecognizer:singleTap];

[self.view addSubview:_Imageview];

 

_Imageview.tag = 2;

 

//这一步是获取上次网络请求下来的图片,如果存在就展示该图片,如果不存在就展示本地保存的名为test的图片

NSMutableData * data = [[NSUserDefaults standardUserDefaults]objectForKey:@"imageu"];

if (data.length>0) {

_Imageview.image = [UIImage imageWithData:data];

}else{

 

_Imageview.image = [UIImage imageNamed:@"028"];

}

 

//下面这段代码,是调用AFN下载文件的方法,异步

NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];

AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:configuration];

NSURL *URL = [NSURL URLWithString:@"http://ac-uRSvH8Hw.clouddn.com/e8e238eaa4b1041c.png"];

NSURLRequest *request = [NSURLRequest requestWithURL:URL];

NSURLSessionDownloadTask *downloadTask = [manager downloadTaskWithRequest:request progress:nil destination:^NSURL *(NSURL *targetPath, NSURLResponse *response) {

 

NSURL *documentsDirectoryURL = [[NSFileManager defaultManager] URLForDirectory:NSDocumentDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:NO error:nil];

return [documentsDirectoryURL URLByAppendingPathComponent:[response suggestedFilename]];

} completionHandler:^(NSURLResponse *response, NSURL *filePath, NSError *error) {

NSLog(@"File downloaded to: %@", filePath);

 

NSData * image = [NSData dataWithContentsOfURL:filePath];

[[NSUserDefaults standardUserDefaults]setObject:image forKey:@"imageu"];

 

 

}];

[downloadTask resume];

 

#pragma mark 不是控制器  跳转的方法   

    添加一个方法

- (UIViewController *)viewController:(UIView *)view{

 

UIResponder *responder = view;

while ((responder = [responder nextResponder]))

if ([responder isKindOfClass: [UIViewController class]])

return (UIViewController *)responder;

 

return nil;

}

 

<!-- 然后self.VC.navigationController  push  pop  present 你乐意想跳那去哪-->

 

}else{

 

LoginVC *LogVC = [[LoginVC alloc]init];

[self.VC.navigationController pushViewController:LogVC animated:YES];

 

 

}

#pragma mark dispatch_get_main_queue 和定时器 NSTimer 的使用  区别 

问题:主页设置根视图时 用了

 

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(5.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{

 

UIWindow *window = [UIApplication sharedApplication].keyWindow;

 

 

HTabBarController *tab = [[HTabBarController alloc] init];

HNavigationController *nv = [[HNavigationController alloc] initWithRootViewController:tab];

window.rootViewController = nv;

 

 

});

 

导致5秒后 自动调回   虽然跳到广告图  时间到后直接返回 产生崩溃 

- (void)UesrClicked{

 

[self.timer invalidate];

 

// 点击多次广告业   只响应最后一次

AVQuery* query = [AVQuery queryWithClassName:@"ADguanggao"];

[query orderByAscending:@"order"];

[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {

if (![self.navigationController.childViewControllers.lastObject isKindOfClass:[HWebView class]]) {

NSString *bannerurl = [objects[0] objectForKey:@"AD_url"];

 

HWebView *webView = [[HWebView alloc] initWithURLString:bannerurl];

 

self.window = [UIApplication sharedApplication].keyWindow;

HTabBarController *tab = [[HTabBarController alloc] init];

HNavigationController *nv = [[HNavigationController alloc] initWithRootViewController:tab];

self.window.rootViewController = nv;

NSLog(@"%@",self.window);

 

[nv pushViewController:webView animated:YES];

 

NSLog(@"点击了广告%@",bannerurl);

 

}

 

}];

 

}

 

解决方案: 添加一个定时器 

 

@property (strong,nonatomic)NSTimer *timer; 

 

在viewDidLoad   直接回调  在点击广告的imageView方法里    [self.timer invalidate]; 取消定时器

 

 self.timer = [NSTimer scheduledTimerWithTimeInterval:6.0 target:self selector:@selector(UserNOClick) userInfo:nil repeats:NO];

 

#pragma mark  加载cell 显示 从第一个 开始  scrollToItemAtIndexPath

 

       [collectionView scrollToItemAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] atScrollPosition:UICollectionViewScrollPositionTop animated:NO];

 

indexPathForRow 的   inSection   第几个cell 的第几个  

 

<!--UICollectionViewScrollPositionNone                 = 0,-->

<!--UICollectionViewScrollPositionTop                  = 1 << 0,-->

<!--UICollectionViewScrollPositionCenteredVertically   = 1 << 1,-->

<!--UICollectionViewScrollPositionBottom               = 1 << 2,-->

<!---->

<!--UICollectionViewScrollPositionLeft                 = 1 << 3,-->

<!--UICollectionViewScrollPositionCenteredHorizontally = 1 << 4,-->

<!--UICollectionViewScrollPositionRight                = 1 << 5-->

 

 

 

#pragma mark 不同的设置颜色 线宽 切割 

//  self.backgroundColor = [UIColor colorWithHexString:@"#EEEEEE"];

self.isPlay = NO;

//        self.layer.borderColor = [UIColor grayColor].CGColor;

//        self.layer.borderWidth = 0.3f;

self.contentView.clipsToBounds = YES;

self.layer.cornerRadius= 5.0f;

 

[self. recordView.collectionView scrollToItemAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] atScrollPosition:UICollectionViewScrollPositionNone animated:NO];

 

 

#pragma mark  po 

在调试阶段这个命令非常有用。通常情况下,为了打印变量的值,我们需要移动鼠标指针并点击和选择打印描述打印值。有时候这种做法对编程并不友好,而po命令让这个过程变得简单且迅速 ,看一个示例。

 

在该示例中,我已经创建了一个命名为str的字符串,并为其赋值。现在要在不移动光标的情况下打印该值,我现在仅需要在输出窗口编写"po variable name"并摁下Enter键。

 

内存泄漏隐患提示:

Potential Leak of an object allocated on line ……

数据赋值隐患提示:

The left operand of …… is a garbage value;

对象引用隐患提示:

Reference-Counted object is used after it is released;

 

 

#pragma mark// RGB 还可以这样  直接写小数 

self.view.backgroundColor = [UIColor colorWithRed:0.92 green:0.75 blue:0.41 alpha:1];

 

 

#pragma mark 封装 代理 调用  

 

 

 

 

#pragma mark  在自定义view 中进行页面跳转 

 

首先  定义一个全局变量     UIViewController *superVC;

 

//然后执行这个方法

 

- (UIViewController *)viewController:(UIView *)view{

 

UIResponder *responder = view;

while ((responder = [responder nextResponder]))

if ([responder isKindOfClass: [UIViewController class]])

return (UIViewController *)responder;

 

return nil;

}

 

 

最后,在你跳转页面的方法中

superVC = [self viewController:self];

 

[superVC.navigationController pushViewController:(UIViewController) animated:YES];

 

这样就可以跳转页面了

 

 

 

#pragma mark   开发中按钮     放大按钮的热区

 

//放大按钮的热区

- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent*)event

{

CGRect bounds = self.bounds;

//若原热区小于44x44,则放大热区,否则保持原大小不变

CGFloat widthDelta = MAX(44.0 - bounds.size.width, 0);

CGFloat heightDelta = MAX(44.0 - bounds.size.height, 0);

bounds = CGRectInset(bounds, -0.5 * widthDelta, -0.5 * heightDelta);

return CGRectContainsPoint(bounds, point);

}

 

#pragma mark  cell中 状态的记录和取消  1

@property (nonatomic,strong)HMImageCell *oldCell;

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {

 

 

HMImageCell *cell = (HMImageCell *)[collectionView  cellForItemAtIndexPath:indexPath];

 

//    if (indexPath.row ==0) {

 

cell.imageView.layer.borderColor = [[UIColor  orangeColor]CGColor];

cell.imageView.layer.borderWidth =2.0f;

 

if (_oldCell) {

 

_oldCell.imageView.layer.borderWidth = 0.0f;

 

}

 

_oldCell = cell;

 

}

 

#pragma mark  cell中 状态的记录和取消  2

 

@property  (nonatomic,strong) ListenCell *oldCell; // 记录上一个cell 的 状态

 

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{

 

ListenCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellID forIndexPath:indexPath];

 

cell.delegate = self;

 

if (_selectIndexPath) {

 

// 防止cell 重用  需要找到条件

if (indexPath.row == _selectIndexPath.row ) {

 

cell.play.tag =1;

[cell  startAnimation];

[cell  runStar];

_oldCell = cell;

 

}else{

 

// 取消 赋值tag  可以 修改状态

//  cell.play.tag = 0;

[cell stopAnimation];

[cell runstop];

 

}

}

 

 

cell.data = self.dataSoure[indexPath.row];

return cell;

 

}

 

 

#pragma ListenCellDelegate

// 上一个cell 停止播放动画 和 旋转  oldcell = cell  在赋值过去

- (void)cellStopAnimationwithCell:(id)cell{

 

if (_oldCell) {

[_oldCell stopAnimation];

[_oldCell runstop];

[_oldCell.play setImage:[UIImage imageNamed:@"kai1"] forState:UIControlStateNormal];

}

 

[cell startAnimation];

[cell runStar];

_oldCell = cell;

NSIndexPath *path = [_collectionView indexPathForCell:cell];

 

_selectIndexPath = path;

}

 

// 防止cell 的重用 需要制nil

- (void)cellStopAnimation{

 

_selectIndexPath = nil;

_oldCell = nil;

}

 

 

#pragma mark  ActionSheetStringPicker 的使用 

//        NSArray *timels = [NSArray arrayWithObjects:@"男", @"女", nil];

//        

//        [ActionSheetStringPicker showPickerWithTitle:@"性别选择"

//                                                rows:timels

//                                    initialSelection:0

//                                           doneBlock:^(ActionSheetStringPicker *picker, NSInteger selectedIndex, id selectedValue) {

//                                               

//                                               // 选择以后做的事

//                                               NSLog(@"Picker: %@, Index: %ld, value: %@",

//                                                     picker, (long)selectedIndex, selectedValue);

//                                               

//                                               if (selectedIndex ==0) {

//                                                   

//                                                _UserdSex.text =  @"男";

//                                               }else if (selectedIndex == 1){

//                                                 _UserdSex.text = @"女";

//                                                   

//                                               }else{

//                                                   

//                                                

//                                                   

//                                               }

//                                               

//                                           }

//                                         cancelBlock:^(ActionSheetStringPicker *picker) {

//                                             // 取消以后做的事

//                                             NSLog(@"Block Picker Canceled");

//                                         }

//                                              origin:self.view];

 

 

#pragma mark  截取字符串  第一个是坐标  第二个是位数  

_UserdPhone.text = [NSString stringWithFormat:@"%@****%@",[[AVUser  currentUser].mobilePhoneNumber substringWithRange:NSMakeRange(0, 3)],[[AVUser  currentUser].username substringWithRange:NSMakeRange(7,4)]];

 

 

#pragma mark  UITextField  添加边框颜色 

 

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField

{

textField.layer.cornerRadius=8.0f;

textField.layer.masksToBounds=YES;

textField.layer.borderColor=[[UIColor orangeColor]CGColor];

textField.layer.borderWidth= 1.0f;

return YES;

}

 

#pragma mark   navigationItem.rightBarButtonItem  添加导航条右侧按钮 

UIBarButtonItem *item = [[UIBarButtonItem alloc]  initWithTitle:@"锁" style:UIBarButtonItemStylePlain target:self action:@selector(clickLock)];

 

self.tabBarController.navigationItem.rightBarButtonItem = item;

#pragma mark  抓包工具  charles 

打开Charles  电脑手机  同一个网络  

同一个 IP   抓取APP的json  挑选 判断比较删除多余url数据   

                

#pragma mark   今日头条json (失效)

1,今日 头条  http://toutiao.com/api/article/recent/?source=2&count=20&category=%E7%AB%A5%E4%B9%A6%E7%BB%98%E6%9C%AC&offset=0  

  

#pragma mark   如何在一行Textfile  显示   图片 

如何在一行显示   图片  textfile  外面包含图片    .leftView    .rightView  

 

#pragma mark  添加占位图片的方法  

 

SDCycleScrollView *banner = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, kBannerHeight) imageURLStringsGroup:arrM];

banner.placeholderImage = [UIImage imageNamed:@"head.jpg"];

 

#pragma mark   leancloud 存储  请求 

 

AVQuery* query = [AVQuery queryWithClassName:AT_BANNER];

[query orderByAscending:@"order"];

[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {

if (error==NULL && objects!= NULL && objects.count > 0)

 

AVQuery* query = [AVQuery queryWithClassName:AT_BANNER];

[query orderByAscending:@"order"];

[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {

NSString *bannerurl = [objects[index] objectForKey:@"Banner_URL"];

HWebView *webView = [[HWebView alloc] initWithURLString:bannerurl];

[self.tabBarController.navigationController pushViewController:webView animated:YES];

 

#pragma mark    提示框 Alert不设置代理添加点击事件 UIAlertController 

 

UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"提示" message:@"是否保存图片"  preferredStyle:UIAlertControllerStyleAlert];

 

UIAlertAction *sureAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {

// [self.navigationController popViewControllerAnimated:YES];

//  self.navigationController pushViewController: animated:<#(BOOL)#>

// [self  clickButton10];

[self.navigationController popViewControllerAnimated:YES];

}];

 

UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {

 

[self.navigationController popViewControllerAnimated:YES];

}];

 

[alertController addAction:sureAction];

[alertController addAction:cancelAction];

[self.parentViewController presentViewController:alertController animated:YES completion:^{

 

}];

 

#pragma mark  跳转控制器

//storyBoard  跳转的方法   记得写 storyboard ID  !!!

UIStoryboard * storyBoard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];

 

[self.navigationController pushViewController:[storyBoard instantiateInitialViewController] animated:YES];

 

  UIStoryboard * storyBoard = [UIStoryboard storyboardWithName:@"PaintVC" bundle:nil];

   [self.navigationController pushViewController:[storyBoard instantiateInitialViewController] animated:YES];

 

        LoginVC *loVC = [[LoginVC  alloc]init];

[self.navigationController pushViewController:loVC animated:YES];

 

 

HWebView *webView = [[HWebView alloc] initWithURLString:data.display_url];

[self.tabBarController.navigationController pushViewController:webView animated:YES];

 

CourseVC *vc = [[CourseVC alloc] init];

[self.tabBarController.navigationController pushViewController:vc animated:YES];

 

 

返回上一个控制器

[self.navigationController  popViewControllerAnimated:YES];

返回根控制器 

[self.navigationController popToRootViewControllerAnimated:NO];

 

#pragma mark  排序的升序 与 降序 

 [query orderByAscending:@"order"];  升序 

- (void)orderByDescending:(NSString *)key;  降序  

 

#pragma mark 如何找你需要的功能 !!!!!!!

UIImage Scanline Floodfill  

谷歌英文翻译  然后github 上搜索 

 

#pragma mark  所谓的适配 不要写死 依据屏幕长宽或者长宽比 

#define fDeviceWidth ([UIScreen mainScreen].bounds.size.width)

#define fDeviceHeight ([UIScreen mainScreen].bounds.size.height)

#define kItemWidthHeigthScale 1.2  //长宽比

 

#pragma mark 判断手机是5s 还是 6s 的方法  可用于约束  缩放比  

 

6s:

<UIScreen: 0x7fba3ae15180; bounds = {{0, 0}, {375, 667}}; mode = <UIScreenMode: 0x7fba3ae15710; size = 750.000000 x 1334.000000>>

5s:

<UIScreen: 0x7f8de0c0b5f0; bounds = {{0, 0}, {320, 568}}; mode = <UIScreenMode: 0x7f8de0c0d0a0; size = 640.000000 x 1136.000000>>

 

例子:

if ([UIScreen mainScreen].bounds.size.width== 320) {

_paintingView = [[PaintingView alloc]initWithFrame:CGRectMake(0, 50, self.view.bounds.size.width, self.view.bounds.size.height*(0.58))];

}else{

_paintingView = [[PaintingView alloc]initWithFrame:CGRectMake(0, 50, self.view.bounds.size.width, self.view.bounds.size.height*(0.62))];

}

#pragma mark   @synthesize 指令

告诉编译器在编译期间 产生getter/setter 方法 

 

#pragma mark   tableView的加载和colloectionView的加载的区别 横屏竖屏 

创建多种重复视图建议使用collectionView    

共同拥有的属性和方法 可以写在 cell 里 

单图cell 的工具  

 

 

#pragma mark   UIimage 默认的userlnteraction  是NO!!!!!

UIImageview 默认的userInteractionEnabled是NO;

UIView的userInteractionEnabled默认是YES。

 

#pragma mark  在UITableView上添加了UITapGestureRecognizer后会导致didSelectRowAtIndexPath失效

在UITableView上添加了UITapGestureRecognizer后会导致didSelectRowAtIndexPath失效,原因是UITapGestureRecognizer会截取了tableView的touch事件,导致无法响应行选择,解决方法是重写UIGestureRecognizerDelegate中的

-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch

{

if ([NSStringFromClass([touch.view class]) isEqualToString:@"UITableViewCellContentView"]) {//如果当前是tableView

//做自己想做的事

return NO;

}

return YES;   

}

 

#pragma mark   控制器之间的传值 方法 代理 KVO  Block   顺传  逆传 

代理方法: A控制器显示 B控制器的数据  A控制器需要加载不同的数据源方法 当B控制器加载进来的时候(点击B控制器Cell的时候或方法时)  

需要:在B的cell .h中  添加代理 或方法  ,m 添加A的头文件  点击方法里遵守代理  

NSIndexPath * indexP = indexPath;

self.delegate.bookIndexPath = indexP;

 

A控制器 .m  导入B控制器的 头文件 

A 的加载cell的方法里  添加不同的数据源 

HImageListCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellID forIndexPath:indexPath];

 

if (self.VC.bookIndexPath.item == YINGHUOQIBING1) {

NSString *imgStr = [NSString stringWithFormat:@"yinghuo%zd.jpg", indexPath.row+1];

cell.imageView.hidden = NO;

cell.imageView.image = [UIImage imageNamed:imgStr];

cell.imgStr = imgStr;

}

if (self.VC.bookIndexPath.item == YINGHUOQIBING2) {

cell.imageView.hidden = NO;

NSString *imgStr = [NSString stringWithFormat:@"yinghuo2%zd.jpg", indexPath.row+1];

cell.imageView.image = [UIImage imageNamed:imgStr];

cell.imgStr = imgStr;

}

 

DLog(@"testest");

 

return cell;

 

#pragma mark  collectionView 多种cell 的嵌套 

(1)两种cell控制器的选择  传值 

  

1。加载cell  

BookCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:celllD forIndexPath:indexPath];

if (self.selectType == 1) {

if (indexPath.row == 0) {

cell.imageView.image = [UIImage imageNamed:@"Book"]

;

//            cell.userName.text = @"AR";

}else if (indexPath.row == 1){

cell.imageView.image = [UIImage imageNamed:@"Book1"];

//            cell.userName.text = @"秘密花园";

} else if (indexPath.row == 2){

cell.imageView.image = [UIImage imageNamed:@"Book1"];

//            cell.userName.text = @"植物";

}else if (indexPath.row == 3){

cell.imageView.image = [UIImage imageNamed:@"Book"];

//            cell.userName.text = @"动物";

}else  if (indexPath.row == 4){

cell.imageView.image = [UIImage imageNamed:@"Book"];

// cell.userName.text = @"建筑";

}else{

cell.imageView.image = [UIImage imageNamed:@"Book1"];

//   cell.userName.text = @"自由创作";

}

}

 

return cell;

 

1.1 跳转方法 

NSIndexPath * indexP = indexPath;

self.delegate.bookIndexPath = indexP;

if (indexPath.row == 1){

 

[self.navigationController  popViewControllerAnimated:YES];

 

}else{

 

[self.navigationController  popViewControllerAnimated:YES];

 

}

 

 

1.2 其他写法

- (void)setSelectType:(NSInteger)selectType{

if (_selectType == selectType) {

return;

}

_selectType = selectType;

[self.collectionView reloadData];

}

- (void)clickHeadButton:(id)sender{

self.selectType = [sender tag];

}

 

在ViewDidload   self.selectType = 1;

 

 

2.1  当1跳转过来  根据1 加载不同2的数据源方法 

 

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{

HImageListCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellID forIndexPath:indexPath];

 

if (self.VC.bookIndexPath.item == YINGHUOQIBING1) {

NSString *imgStr = [NSString stringWithFormat:@"yinghuo%zd.jpg", indexPath.row+1];

cell.imageView.hidden = NO;

cell.imageView.image = [UIImage imageNamed:imgStr];

cell.imgStr = imgStr;

}

if (self.VC.bookIndexPath.item == YINGHUOQIBING2) {

cell.imageView.hidden = NO;

NSString *imgStr = [NSString stringWithFormat:@"yinghuo2%zd.jpg", indexPath.row+1];

cell.imageView.image = [UIImage imageNamed:imgStr];

cell.imgStr = imgStr;

}

 

DLog(@"testest");

 

return cell;

}

 

二(复杂),    三种cell的加载选择  传值 判断 

 

 

2.1加载Cell 

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{

CreateCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:celllD forIndexPath:indexPath];

 

 

if (self.selectType == 1) {

if (indexPath.row == 0) {

cell.imageView.image = [UIImage imageNamed:@"未标题-1.jpg"]

;

cell.userName.text = @"AR";

}else if (indexPath.row == 1){

cell.imageView.image = [UIImage imageNamed:@"hua03.jpg"];

cell.userName.text = @"秘密花园";

} else if (indexPath.row == 2){

cell.imageView.image = [UIImage imageNamed:@"hua04.jpg"];

cell.userName.text = @"植物";

}else if (indexPath.row == 3){

cell.imageView.image = [UIImage imageNamed:@"hua05.jpg"];

cell.userName.text = @"动物";

}else  if (indexPath.row == 4){

cell.imageView.image = [UIImage imageNamed:@"hua03.jpg"];

cell.userName.text = @"建筑";

}else{

cell.imageView.image = [UIImage imageNamed:@"hua01.jpg"];

cell.userName.text = @"自由创作";

}

}

 

return cell;

}

 

- (void)setSelectType:(NSInteger)selectType{

if (_selectType == selectType) {

return;

}

_selectType = selectType;

[self.collectionView reloadData];

}

 

- (void)clickHeadButton:(id)sender{

self.selectType = [sender tag];

}

 

2.2 跳转 

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{

 

if (indexPath.row == 5){

[self  backPaint];

}else{

 

CreatView *loVC = [[CreatView  alloc]init];

loVC.trailIndex = indexPath.item;   // 取巧的方法 

loVC.imgs = @[@"", @""];   // 写成数组最好 

[self.navigationController pushViewController:loVC animated:YES];

}

}

 

2.3 的 加载数据源  

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{

 

// 传值过去

 

PaintFullVC *PVC = [[PaintFullVC alloc]init];

HImageListCell *cell = (HImageListCell *)[self collectionView:collectionView cellForItemAtIndexPath:indexPath];

 

 

PVC.icon = cell.imageView.image;

 

[self.navigationController pushViewController:PVC animated:YES];

 

}

 

#pragma mark UICollectionViewDataSource

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{

NSInteger count;

switch (self.trailIndex) {

case 0:

count = 4;

break;

case 1:

count = 3;

break;

case 2:

count = 3;

case 3:

count =4;

default:

break;

}

return count;

//    return self.imgs.count;

}

 

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{

HImageListCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellId forIndexPath:indexPath];

 

NSString *imgStr = [NSString stringWithFormat:@"Map0%zd_%zd.jpg", indexPath.row+1, self.trailIndex]; // 取巧的数据源加载方法  //后期需要改为数组   

cell.imageView.image = [UIImage imageNamed:imgStr];

 

DLog(@"testest");

return cell;

}

 

#pragma mark 出现导航栏部分黑屏原因 是 隐藏了 需要注销

// 出现导航栏部分黑屏原因 是 隐藏了 需要注销

//- (BOOL)prefersStatusBarHidden

//{

//    return YES;

//}

 

 

#pragma mark  cell 被多次点击只显示一次 URL的方法  

 添加判断 只显示最后一次的方法  

if (![self.tabBarController.navigationController.childViewControllers.lastObject isKindOfClass:[HWebView class]])

根据不同的控制器写不同的判断 

 if(![self.navigationController.childViewControllers.lastObject isKindOfClass:[HWebView class]])

 

#pragma mark UITextFile 的光标处理方法  UI点击手势识别 UITapGestureRecognizer

//设置一个view,为了使将图片添加到这个view上 

在一个View里设置UITapGestureRecognizer 方法 

UIView *aView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 200)];

 

UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];

[aView addGestureRecognizer:tap];

 

- (void)tapAction:(UITapGestureRecognizer *)tap{

[self.UserName resignFirstResponder];

}

 

#pragma mark  Button  和 Label 设置颜色的方式  不要记混  

[_btn setTintColor:[UIColor whiteColor]];

[_Label setTextColor:[UIColor  whiteColor]]; 

#pragma mark  创建出来的View 是不同的原因  _ImageView = [[FloodFillImageView alloc]initWithFrame:CGRectMake(0, 50, self.view.bounds.size.width, self.view.bounds.size.height*(0.62))]; self.view 会遇到的问题  大bug问题  有可能View还没有创建 所以后来创建的地址不一样 导致无法赋值的问题   

 

#pragma mark  ImageView和Image 不同  ImageView 默认的交互是关闭的 一定要打开

self.iconView.userInteractionEnabled = YES;

#pragma mark   录音播放不出来的  播放器创建不了  

 

/* audioPlayerDidFinishPlaying:successfully: is called when a sound has finished playing. This method is NOT called if the player is stopped due to an interruption. */

// 需要添加audioPlayerDidFinishPlaying 完成的方法 

- (void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)player successfully:(BOOL)flag;

 

#pragma mark  tableView 去掉多余显示的cell   设置cell的颜色   设置cell右边的箭头 

 

// 设置前 要设置cell的样式   initWithStyle:UITableViewCellStyleValue1  

if (cell == nil)

{

 

cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cell"];

cell.textLabel.text = @"monalisa";

}

cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

cell.detailTextLabel.text = @"mona";

 

// 取消cell 右侧的箭头 

  cell.accessoryType =  UITableViewCellAccessoryNone;

 

// 设置cell 右边字体的颜色

[cell.textLabel setTextColor:[UIColor orangeColor]];

// 设置cell 右边的箭头 

   cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

 

[self setExtraCellLineHidden:self.tableView];

-(void)setExtraCellLineHidden: (UITableView *)tableView

{

UIView *view = [UIView new];

 

view.backgroundColor = [UIColor clearColor];

 

[tableView setTableFooterView:view];

}

#pragma mark      // 重写UITableView的方法是分割线从最左侧开始

-(void)viewDidLayoutSubviews {

 

if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)]) {

[self.tableView setSeparatorInset:UIEdgeInsetsZero];

 

}

if ([self.tableView respondsToSelector:@selector(setLayoutMargins:)])  {

[self.tableView setLayoutMargins:UIEdgeInsetsZero];

}

 

}

 

-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPat{

if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {

[cell setLayoutMargins:UIEdgeInsetsZero];

}

if ([cell respondsToSelector:@selector(setSeparatorInset:)]){

[cell setSeparatorInset:UIEdgeInsetsZero];

}

}

 

#pragma mark 字符串的截取 

1,字符串从第n 位开端截取,直到最后 (substringFromIndex:n)(包含第 n 位)

2, 字符串截取到第n位  (substringToIndex: n)(第n 位不算再内)

3,substringWithRange: 专门截取字符串的一块肉 

NSMakeRange(4,2)

 

1.定义一个字符串a, 截取a 的某一个项目组,复制给b, b必须是int型

NSString *a = @"1.2.30";

int  b= [[a substringWithRange:NSMakeRange(4,2)] intValue]; 

NSLog(@"a:%@  \n",a  );

NSLog(@"b:%d",b  );

 

Output : 2011-07-05 11:49:08.170 Q[4005:207]   a:1.2.30  

2011-07-05 11:49:08.172 Q[4005:207]            b:30

 

解析如下:substringWithRange: 专门截取字符串的一块肉 

NSMakeRange(4,2)    从第4个字符开端截取,长度为2个字符,(字符串都是从第0个字符开端数的哦~!)

b = [a intValue]; 将 a 转换为 整数型

b = [a floatValue];   将 a 转换为 小数型

b = [a boolValue]; 将 a 转换为 布尔型(true /  false)

b = [a integerValue]; 将 a 转换为 整数型

b = [a longLongValue]; 将 a 转换为 长整型

 

2。 字符串截取到第n位  (substringToIndex: n)(第n 位不算再内)

 

- (void)viewDidLoad

{

NSString  *a = @"i like long dress";

NSString *b = [a substringToIndex:4];

NSLog(@"\n b: %@",b);

}

 

2011-07-11 18:12:40.119 Q[6321:207]      

b: i li

 

3。字符串从第n 位开端截取,直到最后 (substringFromIndex:n)(包含第 n 位)

 

- (void)viewDidLoad

{

NSString  *a = @"i like long dress";

NSString *b = [a substringFromIndex:4];

NSLog(@"\n b: %@",b);

}

 

 

#pragma mark 找bug 的快捷键  

在Xcode 6

 

1.工程导航器:Command+1

 

快速浏览代码、图片以及用户界面文件。

 

2.显示/隐藏导航器面板:Command+0

 

当你在对屏幕进行截图的时候可能会想要隐藏起与你感兴趣内容的无关的部分。假如你想要使用辅助编辑器或者想要设计用户界面并将其连接到代码的时候,这个快捷键会相当有用。

 

3.显示/隐藏实用工具面板:Command+Option+0

 

实用工具面板主要用于编辑用户界面文件时,在你只考虑写代码的时候,就可以隐藏它。

 

4.在辅助编辑器中打开文件:在项目导航器中选中文件执行Option+左键点击操作。

 

一个快速打开Assistant Editor的方式--只需要按住Option键并点击你想要在当前编辑框右边打开的文件即可。

 

Xcode搜索快捷键

 

当你在敲代码的时候,突然想加个什么功能,或者想修改个什么Bug,当然最快的方法就是用查找啦。无需用滚轮穿越百行代码,只需要使用查找,就可以直接跳到特定的代码段。

 

5.搜索导航器(Find Navigator,也就是搜索):Command+Shift+F

 

使用项目搜索可以找到某个变量或方法名的被提到的次数。可以依据实例来匹配,并可忽略大小写字母。另外还可以对查找的变量名进行替换。

 

6.文件跳转栏:Control+6(键入方法/变量名+Enter跳转)

 

跳转至当前代码文件中的代码行。如果文件中有上千行代码,你可以通过该快捷操作来缩小查找范围,从而在需要的地方插入代码以添加新的功能。

 

7.快速打开: Command + Shift + O

 

喜欢使用键盘但不喜欢使用鼠标的人会大爱这个快捷方式,可以直接跳转到某个方法定义或者指定的代码文件。

 

8.跳转栏和快速打开搜索输入快捷键

 

键入第一个字母即可快速切换至某个文件或者找到特定的代码行。比如,在ViewController.Swift文件中,按下Command + Shift + O,然后键入vDL,最先展示的结果是带有

 

viewDidLoad()名的函数。

 

键入首字母,以较少输入搜索更多。

 

9. 程序中(Objective-C或C++编写).h and .m文件间的快速切换: Control + Command + Up Arrow

 

如果你用Objective-C和C++编写程序,或者使用其他语言编写的开源代码,那你可能需要查找现有的代码。你可以使用“Control + Command + Up Arrow”组合键操作在两个

 

相关的文件间快速切换,比如Objective-C中的头文件和实现文件。假如你使用Swift编写代码,这就有点不合适了,因为Swift使用单一代码文件。

 

应用程序编译和清理

 

在体验新应用之前你必须先运行它,不过有时候Xcode会不大给力,不能很好地运行你的项目,这时候你就需要清除不能运行的项目。

 

以下快捷键可帮你在代码编写过程中尽可能少地使用鼠标。

 

10.运行app: Command + R

 

在编写代码的过程中,我通常会使用该快捷键来自由运行应用程序。尽可能地测试应用程序,这样你可以在早期找到并修复应用中的bug。

 

11.清除工程: Command + Shift + K

 

或许有那么一次Xcode运行出现问题,或者应用无法响应,或者出现了意料之外的情况,你首先会想要清除工程并再次运行它。如果这样都还不能解决问题,好吧,关掉Xcode

 

,重新打开。倘若应用程序无法运行,先看看有没有错误信息提示,你可以发挥作为“Googler”的优势来获得帮助。不过这种做法不易太过频繁,它会降低程序的开发速度。它将移除所有的中间文件,而再造这些文件还要花费时间。

 

当运行失败时清除Xcode工程

 

12.构建应用程序: Command + B

 

检查所写代码以确保其正常工作是你经常要做的事情,编译app工程可让你在编写下一个特性之前确定其是否正常工作。即便Xcode在代码编写后会很快进行检查,但也有所延

 

迟,或者给出一些不恰当的错误提示。你无需总是运行应用程序,假如仅仅做一些小的改变,那么编译工作可帮你做一个快速检查,这样可以返回添加下一行代码。

 

编译代码以确保应用程序不存在任何错误问题

文档和帮助

 

在学习过程中,自助学习非常重要,对于没有浏览过Xcode文档帮助的开发者来说,这些快捷键可帮忙查看相关的代码参考,更好地理解苹果提供的代码,从而开发出性能更健壮的app。

 

13.文档和参考: Command + Shift + 0 (Zero)

 

使用Xcode在后台安装文档,并支持离线搜索查看,非常适合外出办公。打开文档和参考,并键入代码中的某个关键字,Xcode文档还提供了一些额外的资源和示例工程。

 

通过Documentation and Reference指南了解如何使用代码

14. 快速帮助: 在类或者方法名上执行Option + Left-click操作

 

内联帮助可帮开发者快速学习类或代码片段的用法。在变量、类、或者方法名上执行Option + Left-click操作来获得更多细节信息。假使你点击了弹出视图底部的参考链接,那么就可以方便地跳转到Xcode提供的文档中。你还可以在变量、类或者方法名上执行Option+双击名称操作,从而更方便地跳转至文档。

 

编写代码时获得快速帮助

 

posted on 2016-08-25 10:14  ZOYOO  阅读(375)  评论(0编辑  收藏  举报