开发中遇到的坑和部分心得2

1.mac下删除项目目录中所有的.svn文件夹

通过下面这个方式可以成功删除(以尝试)
sudo find /Users/justfly/Documents/workspace/justSVN -name ".svn" -exec rm -r {} ;
其中:
/Users/justfly/Documents/workspace/justSVN 是自己的项目路径

2.xcode8调试 self为nil,并且断点不按步骤乱跳

在Project的Build Settings中把Optimization Level 设置成 None 即可。

开发中遇到的坑和部分心得2_第1张图片
修复方法.png

3.如何让编译器忽略一些警告

处女座必备:

1、方法启用告警
    #pragma clang diagnostic push
    #pragma clang diagnostic ignored "-Wdeprecated-declarations"
    //code这里插入相关的代码
    #pragma clang diagnostic pop
 
2.不兼容指针类型
     #pragma clang diagnostic push
     #pragma clang diagnostic ignored "-Wincompatible-pointer-types"
     //code这里插入相关的代码
     #pragma clang diagnostic pop

3.retain cycle
     #pragma clang diagnostic push
     #pragma clang diagnostic ignored "-Warc-retain-cycles"
     //code这里插入相关的代码
     #pragma clang diagnostic pop

4.未使用变量
     #pragma clang diagnostic push
     #pragma clang diagnostic ignored "--Wunused-variable"
     //code这里插入相关的代码
     #pragma clang diagnostic pop

5.selector中使用了不存在的方法名(在使用反射机制通过类名创建类对象的时候会需要的)
     #pragma clang diagnostic push
     #pragma clang diagnostic ignored "-Wundeclared-selector"
     //code这里插入相关的代码
     #pragma clang diagnostic pop
4.项目中如何跳转到指定的页面
UINavigationController * ddd  = (UINavigationController*)[[UIApplication sharedApplication].delegate window].rootViewController;
         NSArray *viewControllers = ddd.viewControllers;
         RCTabBarController * dsc = [viewControllers objectAtIndex:0];
         [dsc selectExchangeShowPage:2 industryCode:goodsCateIndustryCode];
5.在APP推广的时候,推广公司想要获取你公司的APP包,但是你没有推广公司的APP开发账号,这个时候可以打包自己应用的Archives文件给对方,对应目录是:
开发中遇到的坑和部分心得2_第2张图片
Archives.png
6.在swift中集成友盟统计

1.在自己代码中运行成功的集成过程:1按照集成文档第一步在工程中添加.framework,在Link Binary With Libraries-->Add Other添加.framework
2.在自己的桥接文件中引入头文件:#import 并编译
3.didFinishLaunchingWithOptions添加如下代码

在APP代理的didFinishLaunchingWithOptions里面初始化代码为:


        MobClick.setLogEnabled(true)
        let umConfig = UMAnalyticsConfig.init()   
        umConfig.appKey = self.umAppKey  
        MobClick.start(withConfigure: umConfig)

7.如何让tableView滚动到指定的位置
//创建一个指定的NSIndexPath
NSIndexPath *index = [NSIndexPath indexPathForRow:self.dataRow inSection:self.dataCol];
//滚动到指定的位置
 [_tableView selectRowAtIndexPath:index animated:NO scrollPosition:UITableViewScrollPositionTop];
//或者:
[self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:index] atScrollPosition:UITableViewScrollPositionTop animated:YES];
8.iOS键盘常用操作

一、键盘风格,UIKit框架支持8种风格键盘。

typedef enum {

   UIKeyboardTypeDefault, // 默认键盘:支持所有字符
   UIKeyboardTypeASCIICapable, // 支持ASCII的默认键盘
   UIKeyboardTypeNumbersAndPunctuation, // 标准电话键盘,支持+*#等符号
   UIKeyboardTypeURL, // URL键盘,有.com按钮;只支持URL字符
   UIKeyboardTypeNumberPad, //数字键盘
   UIKeyboardTypePhonePad, // 电话键盘
   UIKeyboardTypeNamePhonePad, // 电话键盘,也支持输入人名字
   UIKeyboardTypeEmailAddress, // 用于输入电子邮件地址的键盘
} UIKeyboardType;

//用法用例:
textView.keyboardtype= UIKeyboardTypeNumberPad;

二、键盘外观

typedef enum {

 UIKeyboardAppearanceDefault, // 默认外观:浅灰色
 UIKeyboardAppearanceAlert, //深灰/石墨色
} UIKeyboardAppearance;
//用法用例:
textView.keyboardAppearance=UIKeyboardAppearanceDefault;

三、回车键

typedef enum {

 UIReturnKeyDefault, //默认:灰色按钮,标有Return
 UIReturnKeyGo, //标有Go的蓝色按钮
 UIReturnKeyGoogle, //标有Google的蓝色按钮,用于搜索
 UIReturnKeyJoin, //标有Join的蓝色按钮
 UIReturnKeyNext, //标有Next的蓝色按钮
 UIReturnKeyRoute, //标有Route的蓝色按钮
 UIReturnKeySearch, //标有Search的蓝色按钮
 UIReturnKeySend, //标有Send的蓝色按钮
 UIReturnKeyYahoo, //标有Yahoo!的蓝色按钮,用于搜索
 UIReturnKeyDone, //标有Done的蓝色按钮
 UIReturnKeyEmergencyCall, //紧急呼叫按钮
} UIReturnKeyType;

//用法用例:
textView.returnKeyType=UIReturnKeyGo;

四、自动大写

typedef enum {

 UITextAutocapitalizationTypeNone, //不自动大写
 UITextAutocapitalizationTypeWords, //单词首字母大写
 UITextAutocapitalizationTypeSentences, //句子首字母大写
 UITextAutocapitalizationTypeAllCharacters, //所有字母大写
} UITextAutocapitalizationType;

//用法用例:
textField.autocapitalizationType = UITextAutocapitalizationTypeWords;

五、自动更正

typedef enum {

UITextAutocorrectionTypeDefault,//默认
UITextAutocorrectionTypeNo,//不自动更正
UITextAutocorrectionTypeYes,//自动更正
} UITextAutocorrectionType;

//用法用例:
textField.autocorrectionType = UITextAutocorrectionTypeYes;

六、安全文本输入
textView.secureTextEntry=YES;
开启安全输入主要是用于密码或一些私人数据的输入,此时会禁用自动更正和自此缓存。

七、退出键盘最常用的两种方式
resignFirstResponder
当叫出键盘的那个控件(第一响应者)调用这个方法时,就能退出键盘

endEditing
只要调用这个方法的控件内部存在第一响应者,就能退出键盘
参考资料链接

9.如何自定义tableView右边的锚点View

大家都知道tableView只要实现了代理方法:- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView就能够实现右边的锚点View,但是你会发现系统默认的View会很挤,而且字体、间距都不好设置,所以博主就考虑自己去自定义这一功能。效果图如下:


开发中遇到的坑和部分心得2_第3张图片
效果图.png

下面列举出实现该功能的核心代码:

//属性:
/** 友侧的锚点View */
@property (nonatomic, weak)UIView *rightView;
/** 右侧的锚点View显示的数组数据 */
@property (nonatomic, strong)NSMutableArray *rightViewArray;

//方法:
//懒加载右边的锚点View
- (UIView *)rightView{
    
    if (_rightView == nil) {
        
        if (self.rightViewArray.count <=0) {
            return nil;
        }
        UIView *rightView = [[UIView alloc] initWithFrame:CGRectMake(SCREEN_WIDTH - 15, navigationBarHeigth, 15, SCREEN_HEIGHT - navigationBarHeigth)];
        
        CGFloat W = rightView.LXHWidth;
        CGFloat H = rightView.LXHHeight * 0.7 / self.rightViewArray.count;
        CGFloat Y = (rightView.LXHHeight - rightView.LXHHeight * 0.7) * 0.5;
        CGFloat X = 0;
        for (int i = 0; i < self.rightViewArray.count; ++i) {
            
            UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(X, Y + H * i, W, H)];
            [rightView addSubview:btn];
            [btn setTitle:self.rightViewArray[i] forState:UIControlStateNormal];
            [btn addTarget:self action:@selector(rightViewBtnClick:) forControlEvents:UIControlEventTouchUpInside];
            btn.titleLabel.font = [UIFont systemFontOfSize:12.0];
            btn.titleLabel.textAlignment = NSTextAlignmentCenter;
            [btn setTitleColor:kUIColorFromRGB(0x1e82d2) forState:UIControlStateNormal];
        }
        [self.view insertSubview:rightView atIndex:0];
        _rightView = rightView;
        
    }
    
    [self.view bringSubviewToFront:_rightView];
    return _rightView;
}
//右边锚点View需要显示的数据
- (NSMutableArray *)rightViewArray{
    
    _rightViewArray = [NSMutableArray arrayWithArray:[self.dataArray valueForKeyPath:@"title"]];
    return _rightViewArray;
    
}
//右边按钮被点击的时候tableView滚动到特定位置
- (void)rightViewBtnClick:(UIButton *)btn{
    
    NSInteger index = [self.rightView.subviews indexOfObject:btn];
    
    [self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:index] atScrollPosition:UITableViewScrollPositionTop animated:YES];
    
}

//在tableView默认实现锚点VieW的方法里面替换成自己想要显示的View
- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView{
    if (self.headView.searchTextFiled.text.length <= 0) {
//  默认写法
//        return [self.dataArray valueForKeyPath:@"title"];
//自定义
        self.rightView.hidden = NO;
        return @[@" "];
    }else{
//之所以会有隐藏式需求想要在上面搜索栏搜索的时候隐藏掉右边的锚点View
        self.rightView.hidden = YES;
    }
    return nil;
}

就这样11月份又过去了,为了心中的梦想加油吧。_

你可能感兴趣的:(开发中遇到的坑和部分心得2)