zoukankan      html  css  js  c++  java
  • iOS错误总结

    1.

    00006 请求的url错误

     2.

    00055 是缺少下面两行代码

     _instance.requestSerializer = [AFJSONRequestSerializer serializer];

            

    _instance.responseSerializer = [AFHTTPResponseSerializer serializer];

    3.tableView代理方法不执行什么原因

    1.设置代理 2.tableview的frame 3.代理方法return numberOfRows的返回值 4.数据源没有值5.子类继承自父类时,代理方法没有进行重写,父类的分组的个数已经设置为0,继承,方法的重写(方法名参数相同)方法的重载(方法名相同,但是参数列表不一样)一定要引起相关的重视。

    4.

    更新pod常见问题,新版本替换老版本出现的问题

    1》先更新,清楚缓存 sudo rm -fr ~/.cocoapods/repos/master

    2》网络好的时候,更新完全

    5.

    如果pod出现了重大错误可以将其整体删掉

    Podfile  Podfile.lock  Pods RobotFamily.xcworkspace  然后重新进行pod即可

    6.枚举类型的定义,方便开发者调用

    typedef enum : NSUInteger{

        RequestTypeGet,

        RequestTypePost,

    }RequestType;

    错误代码是-1009网络连接失败

    8. 

    创建数组记得初始化,但是直接set方法里面传递过来的数组可以直接使用

    9.

    @property(nonatomic,strong)RFBaseTypeTableViewController *baseVc;

    控制器只能自己进行管理,控件有个subViews的数组可以进行强引用所以使用weak,但是创建的控制器放在里面必须创建强引用

    View里面的控件创建之后必须进行强引用,应为没有subViews对其进行强引用,保证创建出来的View一直都用,push出去的控制器会一直进行强引用,因为有viewControllers这个数组进行强引用

    下面我会这对这个时间进行详细的说明:http://www.cnblogs.com/chaoyueME/p/5915955.html

    10.

    检测并更新新版本库:update。可以通过查看Pods中已过期的第三方开源库。install & update区别: 例如:Podfile中,,而未指定此开源库版本。install,如果SVProgressHUD已存在Pods中,则直接使用它。但是,update,会重新下载最新版本到Pods中

    11.

    取消tableView以及scrollView适应-64

    12.

    设置textField左边按钮的间距

    UIView *leftVie = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 10, 100)];

        

        textF.leftView = leftVie;

        //设置左边view的显示方式

        textF.leftViewMode = UITextFieldViewModeAlways;

     13.

    xcode升级之后可以在cornerstore中整体的复制版本,保留之前的版本,具体做法,点击之前的版本,右键,copy保留到对应的文件夹即可

    14.

    Can't find keyplane that supports type 4 for keyboard iPhone-PortraitTruffle-NumberPad; using 2425442915_PortraitTruffle_iPhone-Simple-Pad_Default

     目前没有解决办法,但是不影响使用

    15.

    xcode8.0打开相册秒崩的解决办法

     <key>NSCameraUsageDescription</key>

        

        <string>cameraDesciption</string>

        

        <key>NSPhotoLibraryUsageDescription</key>

        

        <string>photoLibraryDesciption</string>

    遗留问题:

     Class PLBuildVersion is implemented in both /Applications/Xcode8.0.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/System/Library/PrivateFrameworks/AssetsLibraryServices.framework/AssetsLibraryServices (0x11b056910) and /Applications/Xcode8.0.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/System/Library/PrivateFrameworks/PhotoLibraryServices.framework/PhotoLibraryServices (0x11a783210). One of the two will be used. Which one is undefined.

    16.

    UISwitch不能设置宽高

    self.switchView.transform = CGAffineTransformMakeScale(0.5, 0.5);只能更改transform

    但是很难设置对其

    //设置开关颜色

     self.switchView.onTintColor= [UIColor blueColor];

    通常使用通过UIButton进行模

    17.

    SVN更新素材,除了上面的两个Applcon和contents.json 剩下的都可以在svn上面直接进行删除,提交,更换

    18.

    子类继承时,切记不要写与父类相同的方法名,不然会覆盖父类的相关方法

     19.

    屏幕适配可以通过masonry或是snipKit,也可以是通过frame的比例进行自动布局,在layoutSubviews(方法里面切记不要创建元素,不要设置约束,约束重定义会报错)的方法里面

    20.监听事件首选是addTarget(系统默认有好多已经写好的键值就是为了减少代理和通知的使用)的方法,其次才是代理和kvo

    1.如果tableView设置为分组的样式(默认是有cell之间的分割线,可以设置颜色),默认有组以及组尾的高度
    需要手动在组头组尾的代理方法中进行组高的设置(如果想设置为0,最好写0.01)
    2.组头如果有标题的话,如果想在上面加一个Label的话,最好是自定义组头
    3.如果设置在tableView的init方法中设置tableView的分组样式的话
    例如重写了tableVeiw的init方法
    //初始化方法
    -(instancetype)init{
        
        self = [super initWithStyle:UITableViewStyleGrouped];
        
        self.tableView.showsVerticalScrollIndicator = NO;
        
        self.tableView.showsHorizontalScrollIndicator = NO;
        
        return self;
    }
    这时候就要考虑,init执行的同时,也操作了tableView,这是会在init的同时执行viewDidLoad的方法
    如果init完紧接着执行了push该tableViewController的相关操作,但push之前给tableView的数据源进行了赋值
    这时候就要考虑   setupUI的相关操作是在数据源的set方法之前还是之后进行的了,否则init了tableViewController还未设置数据就setupUI
    会导致视图无数据
    4.数据文件管理器,保存文件的方式
    //这里将图片放在沙盒的documents文件夹中
    NSString * DocumentsPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
    //文件管理器
    NSFileManager *fileManager = [NSFileManager defaultManager];
    //把刚刚图片转换的data对象拷贝至沙盒中 并保存为image.png
     [fileManager createDirectoryAtPath:DocumentsPath withIntermediateDirectories:YES attributes:nil error:nil];
     [fileManager createFileAtPath:[DocumentsPath stringByAppendingString:@"/image.png"] contents:data attributes:nil];
    5.使用textField监听输入变化,使用UIControlEventEditingChanged键值
    6.只有有footView时才有点击或下拉加载更多
    7.
     NSNumber *sex = nil;
            if (sex==nil) {
             NSLog(@"%ld",[sex integerValue]);//打印0
        }
    8.关于tableView是否进行注册的声明
    dequeueReuseableCellWithIdentifier方法可以不用注册,
    但是必须对获取回来的cell进行判断是否为空,if(cell!=nil)
    但是如果使用dequeueReuseableCellWithIdentifier:forIndexPath则是要进行注册
    9.
    若使用Xib,使用 registerNib: 注册,dequeue时会调用awakeFromNib
    不使用Xib,使用 registerClass: 注册, dequeue时会调用initWithStyle:withReuseableCellIdentifier:
    10.使用sd下视图的时候,获取image
    [ImageView sd_setImageWithURL:url completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
    if (image)//即可得到sd下载的image
    {}
     }];
     11.小技巧,,set方法可以接一层进行
    cell.cellView.urlString =modal.urlString;
    走的是cell中自定义控件cellView中的urlString属性的set方法
    12.pch,只是项目名称/pch 就行了
    865247-20170105231818394-151610222.png
    13.读取一段文本字符串,比如说文本的名称是haha.txt
     // 读取文本
        NSString *text = [NSString stringWithContentsOfFile:[NSBundle.mainBundle URLForResource:@"haha" withExtension:@"txt"].path
                                                   encoding:NSUTF8StringEncoding
                                                      error:nil];
     14.判断系统的版本
    [[UIDevice currentDevice] systemVersion] floatValue]
     15.iOS去评分的网址
    "http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?id=自己的APPID&pageNumber=0&sortOrdering=2&type=Purple+Software&mt=8"
    14.查看沙盒路径
    865247-20170220171721148-672255389.png
    15.
    865247-20170220172544023-49469398.png
     
     
    16.
    865247-20170220172620195-281138318.png
    865247-20170220172627898-1177842367.png
    17.键盘视图记得reload
    865247-20170220172731351-924041773.png
     
    18.两个方法很相近呢
    865247-20170220172807773-1607820428.png
     19.往手机沙河中写入字符串
        NSString *path =  NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0];
        NSString *pathsr = [path stringByAppendingPathComponent:@"文件名"];
         BOOL re = [ss writeToFile:pathsr atomically:YES encoding:NSUTF8StringEncoding error:nil]
    20.同样是只执行一次,但是下面的定时器会崩溃
    //这样不会崩溃
    NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:4 target:self selector:@selector(haha) userInfo:nil repeats:NO];
    //这样会崩溃
    // NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:4 repeats:YES block:^(NSTimer * _Nonnull timer) {
    //  
    // [weakSelf.acView stopAnimating];
    // weakSelf.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSearch target:weakSelf action:@selector(onClickSearchDevices)];
    // }]
    21.如果push的控制器是strong修饰的就回导致控制器不能被释放,不会执行下面的方法
    865247-20170303212204548-939072506.png
    22.
    像一些蓝牙界面的设置,如果是在代理方法中,可能返回的线程并不是主线程,刷新UI可能不起作用,
    记得先获取主线程在进行刷新ui
     dispatch_async(dispatch_get_main_queue(), ^{
            
            mySelf.bluetoothImge.image = [UIImage imageNamed:@"bluetooth_on"];
            
        });
     
    23.button如果是拖控件的方式弄出来的,这是更改他的选中视图可能会渲染成一小块的蓝色,这时候记得把button在视图控件中的属性从system改为custom
    24.
    865247-20170305181745095-291197910.png
    如果是获取蓝牙数据的方法中,绘制以及更改土拍婚的颜色,肯能不成功,因为线程不一致
    25.设备的中心必须用strong
    865247-20170305181850001-350803307.png
     26.AFN中设置网络请求超时时间的地方
    configuration.requestCachePolicy = NSURLRequestUseProtocolCachePolicy;
    configuration.allowsCellularAccess = YES;
    configuration.timeoutIntervalForRequest = 60.0;
    27.切圆角的方式,只切上面的两个角,切圆角要获取视图的bounds,必须已经获取到了视图的bounds,所以一般在
    layoutSubviews中进行,但是记得super
     UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect: 要切圆角的视图.bounds byRoundingCorners:UIRectCornerTopLeft |UIRectCornerTopRight cornerRadii:CGSizeMake(10, 10)];
        CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
        maskLayer.frame = self.viewTemp.bounds;
        maskLayer.path = maskPath.CGPath;
        要切圆角的视图.layer.mask = maskLayer;
    28.
    locationInView:获取到的是手指点击屏幕实时的坐标点;
    translationInView:获取到的是手指移动后,在相对坐标中的偏移量
    29.
    appdelegate里面的通知不用注销,因为代理不会消失
     

    1.减少过期方法的警告

    #pragma clang diagnostic push

    #pragma clang diagnostic ignored "-Wdeprecated-declarations"

    过期方法写在这里

    #pragma clang diagnostic pop

    2.pch的路径

    $(SRCROOT)/$(PRODUCT_NAME)/PrefixHeader.pch

    3.获取沙河路径的方法

    //1,获取沙盒目录路径的函数:
    NSString *homeDir = NSHomeDirectory(); 

    //2,获取Documents目录路径的方法:
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);
    NSString *docDir = [paths objectAtIndex:0];

    //3,获取Caches目录路径的方法:
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory,NSUserDomainMask,YES);
    NSString *cachesDir = [paths objectAtIndex:0];

    //4,获取tmp目录路径的方法:
    NSString *tmpDir = NSTemporaryDirectory();

    4.TPKeyboardAvoiding使用

    导入头文件 TPKeyboardAvoidingScrollView.h 

    增加系统方法

    - (void)loadView{

        [super loadView];

        self.view = [[TPKeyboardAvoidingScrollView alloc]initWithFrame:CGRectMake(0, 0, 屏幕的宽度, 屏幕的高度)];

    }

    5.打开Apache的终端输入语句

    sudo apachectl -k start

    6.pod 

    pod 'MBProgressHUDExtensions', '~> 0.0.1'

     此版本有直接showMessage的方法,或者直接进行手动的导入

    7.pod的版本带上,以免版本更新,重新pod出错

    8._和self的区别

    前者调用该类的setter或getter方法,后者直接获取自己的实例变量。setter方法里面的retainCount会进行+1,后者不会

    9.程序杀死或推到后台applicationDidEndBackground(application:UIApplication){

    }

    10.插入或者替换原来的数据的数据库SQL语句

    11.一个待解觉问题

    12.

    Controller

    self.tableView reloadData];

    View

    self reloadData];

    13

    iOS开发 tableview滚动到最后一行为什么有半行无法显示?

    做了一个类似电话簿的应用。添加页面添加新联系人返回主页面时会自动加到最后一行显示。现在想实现加完回到主界面时自动滚到新加的这一项。用的以下方法,但是总是有半行在屏幕下方滚不出来,求解。

    [self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:[telListData count]-1 inSection:0] atScrollPosition:UITableViewScrollPositionBottom animated:NO];

    tableview 的高度 大于 了self.view 的高度了;

    14.数据刷新完成之后想立即进行滚动制定的行应当先进性刷新再进行滚动

    1.footerView上面按钮的点击事件没有响应,如果是分组的组头组尾可能是没有写组高

    若是整个tableView的footerView或者是headerView,就是没有进行frame的设置

    2.统一使用View可能设置不上,虽然他们的地址是相同的

    ViewController设置View的backgroundColor

    self.view.backgroundColor = [UIColor purpleColor];

    tableViewController设置backgroundColor

    self.tableView.backgroundColor = [UIColor purpleColor];

    3.

    懒加载继承记得改写方法名,(拷贝时出错)方法虽然不会出错,但是一直都不会被调用

    4.

    svn黄叹号可以直接删除掉(橘黄色)delete

    5.

    在Controller里面的cell里面的控件不能进行懒加载,可以在cell的内部进行,但是懒加载就会只创建一次,但是每个cell都需要,结果就是导致Controller进不去,不好判断原因

    6.

    pod 'MBProgressHUDExtensions', '~> 0.0.1' 这个里面有ShowMessage方法

    7.

    关于使用tableView分组技术的小问题

    解决方法:

    在tableViewController里面设置样式

    -(instancetype)init{

        self = [super initWithStyle:UITableViewStyleGrouped]; 

        return self;

    }

    //设置间距 近似于返回0,但是如果不进行设置就会返回12

    -(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{

            return 0.01;

    }

     8.push之前,类的属性赋值直接给属性赋值就好了,但是push之后再赋值就得冲写set方法了

    9.

    不要让一个类承担过多的指责

    10.处理器

    armv7 arm64(真机) i386 x86_6(模拟器)

    11.快捷打印

     NSLog(res?@"插入成功":@"插入失败");

    12.WWDR证书过期

    http://developer.apple.com/certificationauthority/AppleWWDRCA.cer

      新的证书网址,下载下来 ,点击安装

    我的钥匙串,显示  - > 显示过期证书 - > 点击系统 -> 删除过期的证书即可

    13.pch的路径

    $(SRCROOT)/$(PRODUCT_NAME)

    14.一下代码约束报错

    [imageRight mas_makeConstraints:^(MASConstraintMaker *make) {

            make.right.equalTo(mySelf.contentView.mas_right).with.offset(-kFitW(20));

            make.top.equalTo(mySelf.contentView.mas_top).with.offset(0);

            make.width.mas_equalTo(kFitW(8));

            make.height.mas_equalTo(80);

        }];

        [imageV mas_makeConstraints:^(MASConstraintMaker *make) {

            

            make.right.equalTo(imageRight.mas_leading).with.offset(-kFitW(3));

            make.centerY.mas_equalTo(mySelf.contentView.mas_centerY);

            make.width.mas_equalTo(60);

            make.height.mas_equalTo(60);

            

        }];

    报错信息:+[NSLayoutConstraint constraintWithItem:attribute:relatedBy:toItem:attribute:multiplier:constant:]: A constraint cannot be made between a leading/trailing attribute and a right/left attribute. Use leading/trailing for both or neither.'

    原因:

    原因:自动布局 属性对应错误

    Left 对应right

    leading 对应traing

    15:

    Terminating app due to uncaught exception 'Cannot Install Constraint', reason: 'No common superview between views

    原因: 没有添加到父视图上

    16:可以把单独的模块放到.h中,导入pch文件中,这样方便阅读

    color.h 等等

    17:

    将文件保存到沙盒中

    NSString * DocumentsPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];

    //文件管理器

    NSFileManager *fileManager = [NSFileManager defaultManager];

    //把刚刚图片转换的data对象拷贝至沙盒中 并保存为image.png

     [fileManager createDirectoryAtPath:DocumentsPath withIntermediateDirectories:YES attributes:nil error:nil];

     [fileManager createFileAtPath:[DocumentsPath stringByAppendingString:@"/image.png"] contents:data attributes:nil];

    设置图片可以剪切,注意枚举的使用

     UIImage* image = [info objectForKey:@"UIImagePickerControllerEditedImage"];

     图片转化为NSData

    NSData *data;

    //判断用的是不是png格式的图片

            if (UIImagePNGRepresentation(image) == nil)

            {

                data = UIImageJPEGRepresentation(image, 1.0);

            }

            else

            {

                data = UIImagePNGRepresentation(image);

            }

     18:

        NSNumber *sex = nil;

        

        if (sex==nil) {

             NSLog(@"%ld",[sex integerValue]);

        }

  • 相关阅读:
    linux 命令
    Linux中zip压缩和unzip解压缩命令详解
    Sublime Text2.0.2注册码
    Yii框架入门教程(博客教程、权威指南、类手册)
    Redis在PHP中的基本使用案例
    Yii MemCache 应用实例
    javascript数组操作汇总
    CSS进阶学习
    暑期周总结八(2018.8.27-2018.9.2)
    3D轮播图
  • 原文地址:https://www.cnblogs.com/chaoyueME/p/5865576.html
Copyright © 2011-2022 走看看