iOS 错误锦集

   从今天开始,我打算把自己所有遇到的错误,无论大大小小,都保存下来,以供自己反思,少点粗心才能提高效率



1、This application is modifying the autolayout engine from a background thread after the engine was accessed from the main thread. This can lead to engine corruption and weird crashes.


2017-12-20 21:29:03.954058+0800 SwiftLive[3749:2123191] This application is modifying the autolayout engine from a background thread after the engine was accessed from the main thread. This can lead to engine corruption and weird crashes.
 Stack:(
	0   CoreFoundation                      0x000000018cbbaff8 <redacted> + 148
	1   libobjc.A.dylib                     0x000000018b61c538 objc_exception_throw + 56
	2   CoreFoundation                      0x000000018cbbaf28 <redacted> + 0
	3   Foundation                          0x000000018d7ad378 <redacted> + 128
	4   Foundation                          0x000000018d7ad0f8 <redacted> + 76
	5   Foundation                          0x000000018d5f9b48 <redacted> + 132
	6   Foundation                          0x000000018d7abd80 <redacted> + 112
	7   UIKit                               0x0000000192ce9eac <redacted> + 1692
	8   QuartzCore                          0x000000018feda274 <redacted> + 148
	9   UIKit                               0x000000019333a234 <redacted> + 64
	10  QuartzCore                          0x000000018fecede8 <redacted> + 292
	11  QuartzCore                          0x000000018fececa8 <redacted> + 32
	12  QuartzCore                          0x000000018fe4a34c <redacted> + 252
	13  QuartzCore                          0x000000018fe713ac <redacted> + 504
	14  QuartzCore                          0x000000018fe716d8 <redacted> + 244
	15  libsystem_pthread.dylib             0x000000018bc7be20 <redacted> + 572
	16  libsystem_pthread.dylib             0x000000018bc7bb48 <redacted> + 200
	17  libsystem_pthread.dylib             0x000000018bc7b1d8 _pthread_wqthread + 1312
	18  libsystem_pthread.dylib             0x000000018bc7acac start_wqthread + 4
)


从上面的报错信息可以看出,线程在运行的时候子线程修改了主线程UI的布局约束,在iOS开发中,所有的有关界面UI的更新操作必须要在主线程中完成。

在需要的时候,加上下面这句吧:

 
dispatch_async(dispatch_get_main_queue(), ^{     //inset code....   
});

2、attempting to add unsupported attribute: (null)

2017-12-22 16:31:25.357 SwiftLive[3878:2402908] <Unknown>: [BLYLog]  Trapped uncaught exception 'NSInternalInconsistencyException', reason: 'attempting to add unsupported attribute: (null)' 
(
	0   CoreFoundation                      0x000000018cbbaff8 <redacted> + 148
	1   libobjc.A.dylib                     0x000000018b61c538 objc_exception_throw + 56
	2   CoreFoundation                      0x000000018cbbaeb4 <redacted> + 0
	3   Foundation                          0x000000018d653760 <redacted> + 112
	4   SwiftLive                           0x00000001007c47d0 -[MASViewConstraint setSecondViewAttribute:] + 772
	5   SwiftLive                           0x00000001007c5730 __40-[MASViewConstraint equalToWithRelation]_block_invoke + 1756
	6   SwiftLive                           0x00000001007be424 __24-[MASConstraint equalTo]_block_invoke + 100
	7   SwiftLive                           0x000000010017741c __29-[FLGiftSendView configureUI]_block_invoke.66 + 516
	8   SwiftLive                           0x00000001007cbfd8 -[UIView(MASAdditions) mas_makeConstraints:] + 132
	9   SwiftLive                           0x0000000100175b7c -[FLGiftSendView configureUI] + 752
	10  SwiftLive                           0x00000001001757c4 -[FLGiftSendView initWithFrame:] + 332
	11  SwiftLive                           0x000000010045eb2c -[FLChooseGiftsView setupUI] + 3680
	12  SwiftLive                           0x000000010045dbb4 -[FLChooseGiftsView init] + 136
	13  SwiftLive                           0x0000000100291570 -[FLLiveMainInterfaceViewController setupContentView] + 4680
	14  SwiftLive                           0x000000010028f3bc -[FLLiveMainInterfaceViewController setupUI] + 2708
	15  SwiftLive                           0x00000001002881e0 -[FLLiveMainInterfaceViewController viewDidLoad] + 344
	16  UIKit                               0x0000000192cecb04 <redacted> + 1036
	17  UIKit                               0x0000000192d04590 <redacted> + 132
	18  UIKit                               0x0000000192e88e18 <redacted> + 1144
	19  UIKit                               0x0000000192da37bc <redacted> + 676
	20  UIKit                               0x0000000192da3424 <redacted> + 64
	21  UIKit                               0x0000000192da3388 <redacted> + 188
	22  UIKit                               0x0000000192ce9cc0 <redacted> + 1200
	23  QuartzCore                          0x000000018feda274 <redacted> + 148
	24  QuartzCore                          0x000000018fecede8 <redacted> + 292
	25  QuartzCore                          0x000000018fececa8 <redacted> + 32
	26  QuartzCore                          0x000000018fe4a34c <redacted> + 252
	27  QuartzCore                          0x000000018fe713ac <redacted> + 504
	28  QuartzCore                          0x000000018fe71e78 <redacted> + 120
	29  CoreFoundation                      0x000000018cb689a8 <redacted> + 32
	30  CoreFoundation                      0x000000018cb66630 <redacted> + 372
	31  CoreFoundation                      0x000000018cb66a7c <redacted> + 956
	32  CoreFoundation                      0x000000018ca96da4 CFRunLoopRunSpecific + 424
	33  GraphicsServices                    0x000000018e501074 GSEventRunModal + 100
	34  UIKit                               0x0000000192d51c9c UIApplicationMain + 208
	35  SwiftLive                           0x0000000100437dd8 main + 312
	36  libdyld.dylib                       0x000000018baa559c <redacted> + 4
)


    从上面的报错信息,没有什么意外,就是上一个控件布局有问题,或者是布局的顺序有问题,也有可能是约束冲突,或者约束不全。

       使用Masonry要注意约束的完整性。否则就会出现上述报错。


3、今天很坑的一个事情,我想写一个不固定高度的View,View里面放一些控件,我还要给View描边,整个布局布局好以后,发现View里面的控件没有出来,然后我各种看小面包,左边显示控件是存在的,右边的界面却和真机一样没有出来,苦了我又是设置背景颜色调试,又是各种检查布局的,下面是我布局的代码:





   约束检查了一遍又一遍,还是没有任何思路,这里要感谢师父一直给我提示,给我一些调试的方法,我就感觉,应该还是布局的问题,于是我改了如下代码:

    我将 

 make.height.mas_lessThanOrEqualTo(33 * ScreenHeightRatio);
这句代码改成了

make.height.mas_equalTo(33 * ScreenHeightRatio);

结果就可以了,说明用masorny布局,不确定高度的View,是不可以描边等操作的,会出现一系列的问题,可怜我太菜,这个问题调试了很久


4、关于IOS开发之关于UIButton点击没有响应问题


       在做UI界面的时候,确认butten 是最后添加的呀,但是,怎么就不响应点击方法呢?小面包查了一遍又一遍,真的是粗心误大事,哭
        感谢在网上找到的资料,保存一下:

1、如果一个UIButton的frame超出父视图的frame,UIButton还是可以显现的,但响应不了点击事件了,当开发中,遇到UIButton点击没有响应问题时,我们需要输出btn及它父视图的frame,看看btn.frame是否超出view


2、还可以通过Debug--->View Debugging--->show ViewFrames查看按钮上层是否有透明视图。


我的是第一种:UIButten控件大小超出了父控件的大小,所以响应不了点击事件了。

5、-[__NSCFDictionary length]: unrecognized selector sent to instance 0x171c60980' 


     出错在类型上面,我定义的是nsnumber类型,而拿到的是后天返回的是nsstring类型,直接赋值了,小白果然效率低,哎。。。。。。。。。。


    

2017-12-23 19:29:41.451 SwiftLive[4057:2610494] <Unknown>: [BLYLog]  Trapped uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFDictionary length]: unrecognized selector sent to instance 0x171c60980' 
(
	0   CoreFoundation                      0x000000018cbbaff8 <redacted> + 148
	1   libobjc.A.dylib                     0x000000018b61c538 objc_exception_throw + 56
	2   CoreFoundation                      0x000000018cbc1ef4 <redacted> + 0
	3   CoreFoundation                      0x000000018cbbef54 <redacted> + 916
	4   CoreFoundation                      0x000000018cabad4c _CF_forwarding_prep_0 + 92
	5   UIKit                               0x0000000192cf66c8 <redacted> + 312
	6   SwiftLive                           0x000000010014f574 -[FLGiftSendView tableView:didSelectRowAtIndexPath:] + 900
	7   UIKit                               0x0000000192e17a9c <redacted> + 1200
	8   UIKit                               0x0000000192ec7820 <redacted> + 268
	9   UIKit                               0x0000000192f79594 <redacted> + 292
	10  UIKit                               0x0000000192f6b630 <redacted> + 528
	11  UIKit                               0x0000000192cdf28c <redacted> + 132
	12  CoreFoundation                      0x000000018cb689a8 <redacted> + 32
	13  CoreFoundation                      0x000000018cb66630 <redacted> + 372
	14  CoreFoundation                      0x000000018cb66a7c <redacted> + 956
	15  CoreFoundation                      0x000000018ca96da4 CFRunLoopRunSpecific + 424
	16  GraphicsServices                    0x000000018e501074 GSEventRunModal + 100
	17  UIKit                               0x0000000192d51c9c UIApplicationMain + 208
	18  SwiftLive                           0x000000010040ba24 main + 312
	19  libdyld.dylib                       0x000000018baa559c <redacted> + 4
)

解决:NSString 转 NSNumber :

lastSeletNum = @([self.comeShowArray[indexPath.row][@"gift_num"] integerValue]);


6、不能同时比较:


         
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值