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  + 148
	1   libobjc.A.dylib                     0x000000018b61c538 objc_exception_throw + 56
	2   CoreFoundation                      0x000000018cbbaf28  + 0
	3   Foundation                          0x000000018d7ad378  + 128
	4   Foundation                          0x000000018d7ad0f8  + 76
	5   Foundation                          0x000000018d5f9b48  + 132
	6   Foundation                          0x000000018d7abd80  + 112
	7   UIKit                               0x0000000192ce9eac  + 1692
	8   QuartzCore                          0x000000018feda274  + 148
	9   UIKit                               0x000000019333a234  + 64
	10  QuartzCore                          0x000000018fecede8  + 292
	11  QuartzCore                          0x000000018fececa8  + 32
	12  QuartzCore                          0x000000018fe4a34c  + 252
	13  QuartzCore                          0x000000018fe713ac  + 504
	14  QuartzCore                          0x000000018fe716d8  + 244
	15  libsystem_pthread.dylib             0x000000018bc7be20  + 572
	16  libsystem_pthread.dylib             0x000000018bc7bb48  + 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] : [BLYLog]  Trapped uncaught exception 'NSInternalInconsistencyException', reason: 'attempting to add unsupported attribute: (null)' 
(
	0   CoreFoundation                      0x000000018cbbaff8  + 148
	1   libobjc.A.dylib                     0x000000018b61c538 objc_exception_throw + 56
	2   CoreFoundation                      0x000000018cbbaeb4  + 0
	3   Foundation                          0x000000018d653760  + 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  + 1036
	17  UIKit                               0x0000000192d04590  + 132
	18  UIKit                               0x0000000192e88e18  + 1144
	19  UIKit                               0x0000000192da37bc  + 676
	20  UIKit                               0x0000000192da3424  + 64
	21  UIKit                               0x0000000192da3388  + 188
	22  UIKit                               0x0000000192ce9cc0  + 1200
	23  QuartzCore                          0x000000018feda274  + 148
	24  QuartzCore                          0x000000018fecede8  + 292
	25  QuartzCore                          0x000000018fececa8  + 32
	26  QuartzCore                          0x000000018fe4a34c  + 252
	27  QuartzCore                          0x000000018fe713ac  + 504
	28  QuartzCore                          0x000000018fe71e78  + 120
	29  CoreFoundation                      0x000000018cb689a8  + 32
	30  CoreFoundation                      0x000000018cb66630  + 372
	31  CoreFoundation                      0x000000018cb66a7c  + 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  + 4
)


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

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


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


iOS 错误锦集_第1张图片



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

    我将 

 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] : [BLYLog]  Trapped uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFDictionary length]: unrecognized selector sent to instance 0x171c60980' 
(
	0   CoreFoundation                      0x000000018cbbaff8  + 148
	1   libobjc.A.dylib                     0x000000018b61c538 objc_exception_throw + 56
	2   CoreFoundation                      0x000000018cbc1ef4  + 0
	3   CoreFoundation                      0x000000018cbbef54  + 916
	4   CoreFoundation                      0x000000018cabad4c _CF_forwarding_prep_0 + 92
	5   UIKit                               0x0000000192cf66c8  + 312
	6   SwiftLive                           0x000000010014f574 -[FLGiftSendView tableView:didSelectRowAtIndexPath:] + 900
	7   UIKit                               0x0000000192e17a9c  + 1200
	8   UIKit                               0x0000000192ec7820  + 268
	9   UIKit                               0x0000000192f79594  + 292
	10  UIKit                               0x0000000192f6b630  + 528
	11  UIKit                               0x0000000192cdf28c  + 132
	12  CoreFoundation                      0x000000018cb689a8  + 32
	13  CoreFoundation                      0x000000018cb66630  + 372
	14  CoreFoundation                      0x000000018cb66a7c  + 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  + 4
)

解决:NSString 转 NSNumber :

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


6、不能同时比较:


          我将一个string类型的字符串转换成int 类型,然后对齐比较大小,结果报了如下警告:
Comparison of constant 10 with boolean expression is always true
呼呼,不开森,iOS不能同时比较耶,要用&& 链接去比较
错误的代码如下:

    if (1 <= [listModle.liver_grade integerValue] <= 10) {
        self.popularityImg.image = [UIImage imageNamed:@"icon_little_anchorlevel1_10"];
    }else if (11 <= [listModle.liver_grade integerValue] <= 20){
        self.popularityImg.image = [UIImage imageNamed:@"icon_little_anchorlevel11_20"];
    }else if (21 <= [listModle.liver_grade integerValue] <= 30){
        self.popularityImg.image = [UIImage imageNamed:@"icon_little_anchorlevel21_30"];
    }else if (31 <= [listModle.liver_grade integerValue] <= 40){
        self.popularityImg.image = [UIImage imageNamed:@"icon_little_anchorlevel31_40"];
    }else if (41 <= [listModle.liver_grade integerValue] <= 50){
        self.popularityImg.image = [UIImage imageNamed:@"icon_little_anchorlevel41_50"];
    }

正确的代码如下:

NSInteger grade = [listModle.liver_grade integerValue];
    if (1 <= grade  && grade <= 10) {
        self.popularityImg.image = [UIImage imageNamed:@"icon_little_anchorlevel1_10"];
    }else if (11 <= grade && grade <= 20){
        self.popularityImg.image = [UIImage imageNamed:@"icon_little_anchorlevel11_20"];
    }else if (21 <= grade && grade <= 30){
        self.popularityImg.image = [UIImage imageNamed:@"icon_little_anchorlevel21_30"];
    }else if (31 <= grade && grade <= 40){
        self.popularityImg.image = [UIImage imageNamed:@"icon_little_anchorlevel31_40"];
    }else if (41 <= grade && grade <= 50){
        self.popularityImg.image = [UIImage imageNamed:@"icon_little_anchorlevel41_50"];
    }

7、应用在iPhone5 iPhone5s 上不全屏,上下各有黑块

在网上找到如下原因:
a、 没有添加适配iPhone的  640 * 1136 分辨率的图片
b、 整个工程中,有没有一个地方在设置画面高度时候使用了固定值480或568等,一般都是直接获取屏幕大小,然后再设置画面大小的。
c、如果用的有xib,就在xib里面设置一下view的自动布局;如果用的是纯代码,就手动设置UIView的autoLayout 
d、UI给的图片有问题,或者自己没有把图片的位置放好

我就是属于第四种,各种办法试了试,如下配置正确:
iOS 错误锦集_第2张图片

启动图也都有:

iOS 错误锦集_第3张图片


结果就是有如下问题:

iOS 错误锦集_第4张图片


我就把启动图都删了,换上上家公司的启动图片,结果没有问题,所有就是现在UI给的启动图有问题喽,让UI重新学习iOS启动图切图,放上,就木有问题啦!

8、CollectionView 上拉加载更多 刷新闪屏


在网上找了很多方法,不过好像并没有特别有用,最后采取的办法有如下几种,不过都感觉效果一般,先记下来,后面再试试:
    方法一:
[UIView setAnimationsEnabled:NO];
 
[collectionView performBatchUpdates:^{
    [collectionView reloadData];
} completion:^(BOOL finished) {
    [UIView setAnimationsEnabled:YES];
}];

   方法二:
[UIView animateWithDuration:0 animations:^{
    [collectionView performBatchUpdates:^{
        [collectionView reloadData];
    } completion:nil];
}];

注意:performBatchUpdates  这个方法是collectionView原来有数据的时候,上拉刷新才能用,第一次 reloaData 就调用这个方法,会崩溃的呦 QAQ

   方法三:

NSMutableArray*indexPaths = [[NSMutableArray alloc] init];

for ( inti =0; i < model.mediumArr.count;  i ++) {

NSIndexPath *indexPath = [NSIndexPath indexPathForRow: self.dataSource.count+ i in Section: 0];

[indexPaths addObject: indexPath];

}

[self.dataSource addObjectsFromArray: model.mediumArr];

[self.collectionView insertItemsAtIndexPaths: indexPaths];

[UIView performWithoutAnimation:^{

[self.collectionView reloadItemsAtIndexPaths: indexPaths];

}];

注:model.mediumArr为加载进来的新数据源,也就是上啦加载出来的数据(数组)

具体想用哪个方法,自己试试看看拿个更好一些,后面找到更好的方法,会持续更新



9、图片填充方式:

   1、UIViewContentModeScaleAspectFit, //这个图片都会在view里面显示,并且比例不变 这就是说 如果图片和view的比例不一样 就会有留白
    
   2、UIViewContentModeScaleAspectFill, // 这是整个view会被图片填满,图片比例不变 ,这样图片显示就会大于view
   
   3、Scale to Fill: 缩放图片,使图片充满容器。没有aspect,图片未必保持长宽比例协调,有可能会拉伸至变形。

      4、 UIViewContentModeCenter  中间为中心

   5、UIViewContentModeTop  以上面为主

   6、UIViewContentModeBottom   以下面为主

   7、UIViewContentModeLeft   以左边为主

   8、UIViewContentModeRight

   9、UIViewContentModeTopLeft

   10、UIViewContentModeTopRight

   11、UIViewContentModeBottomLeft

   12、UIViewContentModeBottomRight

   13、UIViewContentModeLeft

   14、UIViewContentModeLeft

   15、UIViewContentModeLeft

10、'-[__NSCFString objectForKeyedSubscript:]: unrecognized selector sent to instance 0x102288570' 


报错信息如下:

2017-12-28 19:38:14.259 SwiftLive[1327:1606209] : [BLYLog]  Trapped uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString objectForKeyedSubscript:]: unrecognized selector sent to instance 0x102288570' 
(
	0   CoreFoundation                      0x0000000186d461d8  + 148
	1   libobjc.A.dylib                     0x000000018578055c objc_exception_throw + 56
	2   CoreFoundation                      0x0000000186d4d278  + 0
	3   CoreFoundation                      0x0000000186d4a278  + 916
	4   CoreFoundation                      0x0000000186c4459c _CF_forwarding_prep_0 + 92
	5   SwiftLive                           0x00000001001a1e3c -[FLAttentionViewController collectionView:didSelectItemAtIndexPath:] + 476
	6   UIKit                               0x000000018cdb9ad4  + 596
	7   UIKit                               0x000000018cdb9468  + 596
	8   UIKit                               0x000000018cd34e84  + 336
	9   UIKit                               0x000000018cd7f500  + 60
	10  UIKit                               0x000000018cd34e84  + 336
	11  UIKit                               0x000000018cd7f500  + 60
	12  UIKit                               0x000000018cd34e84  + 336
	13  UIKit                               0x000000018cd7f500  + 60
	14  UIKit                               0x000000018d166c90  + 4484
	15  UIKit                               0x000000018d162d28  + 1164
	16  UIKit                               0x000000018d162848  + 408
	17  UIKit                               0x000000018d161b04  + 268
	18  UIKit                               0x000000018cbd0a44  + 2960
	19  UIKit                               0x000000018cba152c  + 340
	20  UIKit                               0x000000018d38ea54  + 2736
	21  UIKit                               0x000000018d3884bc  + 784
	22  CoreFoundation                      0x0000000186cf4278  + 24
	23  CoreFoundation                      0x0000000186cf3bc0  + 524
	24  CoreFoundation                      0x0000000186cf17c0  + 804
	25  CoreFoundation                      0x0000000186c20048 CFRunLoopRunSpecific + 444
	26  GraphicsServices                    0x00000001886a6198 GSEventRunModal + 180
	27  UIKit                               0x000000018cc0c2fc  + 684
	28  UIKit                               0x000000018cc07034 UIApplicationMain + 208
	29  SwiftLive                           0x000000010037b6d0 main + 312
	30  libdyld.dylib                       0x0000000185c045b8  + 4
)


   刚一开始看,以为是数据解析错误,但是明明是看着打印出的数据解析的,没有问题啊,郁闷的宝宝又去找师傅,师父说,肯定是你没字典转模型啊

确实,后台返的数组里面嵌套有字典,然后忘了写:

- (void)setValue:(id)value forKey:(NSString *)key
{
    if ([key isEqualToString:@"live_info"])
    {
        [super setValue:value forKey:key];
    }else
    {
        NSString *string = [NSString stringWithFormat:@"%@", value];
        [super setValue:string forKey:key];
    }
    
}

师父果然腻害,笨笨的我,总是丢三落四


11、大家新年快乐,今天继续上班,遇到了一个小小的问题:

*** -[__NSArrayM insertObject:atIndex:]: object cannot be nil


2018-01-02 14:43:32.923 SwiftLive[1046:427525] : [BLYLog]  Trapped uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSArrayM insertObject:atIndex:]: object cannot be nil' 
(
	0   CoreFoundation                      0x0000000181f2aff8  + 148
	1   libobjc.A.dylib                     0x000000018098c538 objc_exception_throw + 56
	2   CoreFoundation                      0x0000000181e0c898 CFStringConvertNSStringEncodingToEncoding + 0
	3   SwiftLive                           0x000000010018e110 -[FLRefreshHeaderView imagesArr] + 336
	4   SwiftLive                           0x000000010018e684 -[FLRefreshHeaderView setRefreshState:] + 60
	5   SwiftLive                           0x000000010018da74 -[FLRefreshHeaderView refreshView] + 792
	6   SwiftLive                           0x000000010018f178 -[FLRefreshHeaderView setState:] + 1516
	7   SwiftLive                           0x00000001007c1aa0 -[MJRefreshComponent initWithFrame:] + 200
	8   SwiftLive                           0x000000010018d700 -[FLRefreshHeaderView init] + 76
	9   SwiftLive                           0x00000001007c524c +[MJRefreshHeader headerWithRefreshingTarget:refreshingAction:] + 92
	10  SwiftLive                           0x000000010021bd20 -[FLLiveListViewController setUpRefreshView] + 88
	11  SwiftLive                           0x000000010021bb40 -[FLLiveListViewController viewDidLoad] + 876
	12  UIKit                               0x000000018805cb04  + 1036
	13  UIKit                               0x000000018805c6e0  + 28
	14  SwiftLive                           0x000000010012b0ec -[FLHomeViewController collectionView:cellForItemAtIndexPath:] + 436
	15  UIKit                               0x00000001889564a0  + 448
	16  UIKit                               0x00000001880bd3f0  + 3820
	17  UIKit                               0x00000001880b8018  + 300
	18  UIKit                               0x0000000188059cc0  + 1200
	19  QuartzCore                          0x000000018524a274  + 148
	20  QuartzCore                          0x000000018523ede8  + 292
	21  QuartzCore                          0x000000018523eca8  + 32
	22  QuartzCore                          0x00000001851ba34c  + 252
	23  QuartzCore                          0x00000001851e13ac  + 504
	24  UIKit                               0x00000001882f4840  + 140
	25  CoreFoundation                      0x0000000181ed930c  + 20
	26  CoreFoundation                      0x0000000181ed8b28  + 288
	27  CoreFoundation                      0x0000000181ed6998  + 728
	28  CoreFoundation                      0x0000000181e06da4 CFRunLoopRunSpecific + 424
	29  GraphicsServices                    0x0000000183871074 GSEventRunModal + 100
	30  UIKit                               0x00000001880c1c9c UIApplicationMain + 208
	31  SwiftLive                           0x000000010044771c main + 312
	32  libdyld.dylib                       0x0000000180e1559c  + 4
)

这个出错的原因主要是,我们的一个帧动画需要替换,UI直接用我原来的图的名称命名的,便于我替换,不过帧的多少是不一样的,我把图片直接拉进去,代码里面的帧数改了,多余的帧的图片却忘记拉进项目,找不到对应的图,自然崩溃


12、-[__NSCFNumber length]: unrecognized selector sent to instance 0xb000000000000643

2018-01-03 14:39:38.703 SwiftLive[1681:2148751] : [BLYLog]  Trapped uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFNumber length]: unrecognized selector sent to instance 0xb000000000000643' 
(
	0   CoreFoundation                      0x0000000186d461d8  + 148
	1   libobjc.A.dylib                     0x000000018578055c objc_exception_throw + 56
	2   CoreFoundation                      0x0000000186d4d278  + 0
	3   CoreFoundation                      0x0000000186d4a278  + 916
	4   CoreFoundation                      0x0000000186c4459c _CF_forwarding_prep_0 + 92
	5   UIKit                               0x000000018cbab7bc  + 108
	6   UIKit                               0x000000018cbab6b4  + 128
	7   UIKit                               0x000000018cca1afc  + 96
	8   UIKit                               0x000000018cca18f0  + 52
	9   UIKit                               0x000000018cca1458  + 488
	10  UIKit                               0x000000018d4f3b78  + 76
	11  UIKit                               0x000000018d4f289c  + 192
	12  UIKit                               0x000000018d4f2be4  + 632
	13  UIKit                               0x000000018d4f2b6c  + 512
	14  UIKit                               0x000000018d4f2b6c  + 512
	15  UIKit                               0x000000018d4f2b6c  + 512
	16  UIKit                               0x000000018d4f2b6c  + 512
	17  UIKit                               0x000000018d4f2b6c  + 512
	18  UIKit                               0x000000018d4f2b6c  + 512
	19  Foundation                          0x0000000187775480  + 168
	20  UIKit                               0x000000018d4f338c  + 84
	21  UIKit                               0x000000018d4f254c  + 136
	22  UIKit                               0x000000018d4f2f94  + 164
	23  UIKit                               0x000000018d4f3f00  + 364
	24  UIKit                               0x000000018ce9add4  + 180
	25  UIKit                               0x000000018cb9e220  + 1196
	26  QuartzCore                          0x000000018a05e188  + 148
	27  QuartzCore                          0x000000018a052e64  + 292
	28  QuartzCore                          0x000000018a052d24  + 32
	29  QuartzCore                          0x0000000189fcf7ec  + 252
	30  QuartzCore                          0x0000000189ff6c58  + 512
	31  QuartzCore                          0x0000000189ff7678  + 120
	32  CoreFoundation                      0x0000000186cf37dc  + 32
	33  CoreFoundation                      0x0000000186cf140c  + 372
	34  CoreFoundation                      0x0000000186cf189c  + 1024
	35  CoreFoundation                      0x0000000186c20048 CFRunLoopRunSpecific + 444
	36  GraphicsServices                    0x00000001886a6198 GSEventRunModal + 180
	37  UIKit                               0x000000018cc0c2fc  + 684
	38  UIKit                               0x000000018cc07034 UIApplicationMain + 208
	39  SwiftLive                           0x00000001003f7454 main + 312
	40  libdyld.dylib                       0x0000000185c045b8  + 4
)

每次从后台拿到值的时候,总忘判断后天传过来的值的类型,呢,又出错了,后台的给我的是长整型的变量,我赋值给了string类型。


13、the view returned from -collectionView:viewForSupplementaryElementOfKind:atIndexPath (UICollectionElementKindSectionHeader, {length = 2, path = 0 - 0}) was not retrieved by calling -dequeueReusableSupplementaryViewOfKind:withReuseIdentifier:forIndexPath: or is nil ((null))


2018-01-03 16:00:21.895 SwiftLive[1712:2166430] : [BLYLog]  Trapped uncaught exception 'NSInternalInconsistencyException', reason: 'the view returned from -collectionView:viewForSupplementaryElementOfKind:atIndexPath (UICollectionElementKindSectionHeader, {length = 2, path = 0 - 0}) was not retrieved by calling -dequeueReusableSupplementaryViewOfKind:withReuseIdentifier:forIndexPath: or is nil ((null))' 
(
	0   CoreFoundation                      0x0000000186d461d8  + 148
	1   libobjc.A.dylib                     0x000000018578055c objc_exception_throw + 56
	2   CoreFoundation                      0x0000000186d46094  + 0
	3   Foundation                          0x00000001877d379c  + 112
	4   UIKit                               0x000000018cd24044  + 932
	5   UIKit                               0x000000018cc02678  + 3868
	6   UIKit                               0x000000018cbfd0a4  + 288
	7   UIKit                               0x000000018cb9e220  + 1196
	8   QuartzCore                          0x000000018a05e188  + 148
	9   QuartzCore                          0x000000018a052e64  + 292
	10  QuartzCore                          0x000000018a052d24  + 32
	11  QuartzCore                          0x0000000189fcf7ec  + 252
	12  QuartzCore                          0x0000000189ff6c58  + 512
	13  QuartzCore                          0x0000000189ff7678  + 120
	14  CoreFoundation                      0x0000000186cf37dc  + 32
	15  CoreFoundation                      0x0000000186cf140c  + 372
	16  CoreFoundation                      0x0000000186cf189c  + 1024
	17  CoreFoundation                      0x0000000186c20048 CFRunLoopRunSpecific + 444
	18  GraphicsServices                    0x00000001886a6198 GSEventRunModal + 180
	19  UIKit                               0x000000018cc0c2fc  + 684
	20  UIKit                               0x000000018cc07034 UIApplicationMain + 208
	21  SwiftLive                           0x0000000100397478 main + 312
	22  libdyld.dylib                       0x0000000185c045b8  + 4
)

这个不是太确定,应该是要判断collectionView的header的section要确定下来,不能直接返回nil?有大神看到了帮忙解答下,蟹蟹。


14、-[__NSSingleObjectArrayI objectForKey:]: unrecognized selector sent to instance 0x174011cd0

2018-01-03 16:12:37.485 SwiftLive[1725:2170098] : [BLYLog]  Trapped uncaught exception 'NSInvalidArgumentException', reason: '-[__NSSingleObjectArrayI objectForKey:]: unrecognized selector sent to instance 0x174011cd0' 
(
	0   CoreFoundation                      0x0000000186d461d8  + 148
	1   libobjc.A.dylib                     0x000000018578055c objc_exception_throw + 56
	2   CoreFoundation                      0x0000000186d4d278  + 0
	3   CoreFoundation                      0x0000000186d4a278  + 916
	4   CoreFoundation                      0x0000000186c4459c _CF_forwarding_prep_0 + 92
	5   Foundation                          0x00000001877ea800  + 212
	6   SwiftLive                           0x000000010036ac88 -[FLDiscoveryViewController dealRequestDataErrorWithOffset:] + 1092
	7   SwiftLive                           0x000000010036a5c4 -[FLDiscoveryViewController refreshData] + 404
	8   SwiftLive                           0x00000001006eac0c __47-[MJRefreshComponent executeRefreshingCallback]_block_invoke + 372
	9   libdispatch.dylib                   0x0000000101f1925c _dispatch_call_block_and_release + 24
	10  libdispatch.dylib                   0x0000000101f1921c _dispatch_client_callout + 16
	11  libdispatch.dylib                   0x0000000101f1e284 _dispatch_main_queue_callback_4CF + 1200
	12  CoreFoundation                      0x0000000186cf3f2c  + 12
	13  CoreFoundation                      0x0000000186cf1b18  + 1660
	14  CoreFoundation                      0x0000000186c20048 CFRunLoopRunSpecific + 444
	15  GraphicsServices                    0x00000001886a6198 GSEventRunModal + 180
	16  UIKit                               0x000000018cc0c2fc  + 684
	17  UIKit                               0x000000018cc07034 UIApplicationMain + 208
	18  SwiftLive                           0x000000010036f4a0 main + 312
	19  libdyld.dylib                       0x0000000185c045b8  + 4
)

这里就狠坑啦,主要还是窝是个小白,应该是字典转模型的,但是我取出来的是数组,而不是字段,根据打印,一看就是数组,怎么会不蹦捏!

字典:
{
    avatar = "http://tx-upload.hk.ufileos.com/c229b79525a8a1e276d8e7c6817aab26.jpg";
    "avatar_small" = "http://tx-upload.hk.ufileos.com/cca6661843afcd4953539a0dc220da50.jpg";
    country = "";
    "create_time" = 1514957449;
    "current_count" = 0;
    "end_time" = 0;
    gender = 0;
    "great_sort" = 0;
    "hls_endpoint" = "http://hls.ylive.avazuinc.com:9090/hls/av3598/index.m3u8";
    "hot_sort" = 0;
    "like_sort" = 0;
    "live_id" = 3598;
    "live_pic" = "";
    "liver_exp" = 208080;
    "liver_grade" = 4;
    "liver_next_exp" = 319300;
    "new_sort" = 0;
    nick = test123;
    "people_count" = 300;
    signature = "";
    status = 2;
    "streaming_endpoint" = "rtmp://source.publish.olivestream.tv/live/av3598";
    title = "test123 on live";
    uid = 828;
    "update_time" = 1514957449;
    "viewing_endpoint" = "http://rtmp.pull.olivestream.tv/live/av3598.flv";
}


数组:

(
{
    avatar = "http://tx-upload.hk.ufileos.com/c229b79525a8a1e276d8e7c6817aab26.jpg";
    "avatar_small" = "http://tx-upload.hk.ufileos.com/cca6661843afcd4953539a0dc220da50.jpg";
    country = "";
    "create_time" = 1514957449;
    "current_count" = 0;
    "end_time" = 0;
    gender = 0;
    "great_sort" = 0;
    "hls_endpoint" = "http://hls.ylive.avazuinc.com:9090/hls/av3598/index.m3u8";
    "hot_sort" = 0;
    "like_sort" = 0;
    "live_id" = 3598;
    "live_pic" = "";
    "liver_exp" = 208080;
    "liver_grade" = 4;
    "liver_next_exp" = 319300;
    "new_sort" = 0;
    nick = test123;
    "people_count" = 300;
    signature = "";
    status = 2;
    "streaming_endpoint" = "rtmp://source.publish.olivestream.tv/live/av3598";
    title = "test123 on live";
    uid = 828;
    "update_time" = 1514957449;
    "viewing_endpoint" = "http://rtmp.pull.olivestream.tv/live/av3598.flv";
}
)


15、网络状态不好的时候,明明设置了刷新超时,却明显超过了自己设置的超时时间,还在加载QAQ

原来代码如下:


感谢师父告诉我,这样是不对滴,

timeoutInterval  已经没有了作用。不管是同步还是异步。

这个问题只有在3.0以及之后的os中才有的,而且只有在当调用了setHTTPBody之后才会出现timeout失效。这个是苹果公司对URL Loading System的在iOS3.0中的一个改动,所有要改代码:


[request setTimeoutInterval:10.0f];

改成

[self.manager.requestSerializer setTimeoutInterval:10.0f];

感谢师父!

16、-[__NSCFNumber boundingRectWithSize:options:attributes:context:]: unrecognized selector sent to instance 0xb000000000d33a13


2018-01-04 21:03:39.929 SwiftLive[1935:2427284] : [BLYLog]  Trapped uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFNumber boundingRectWithSize:options:attributes:context:]: unrecognized selector sent to instance 0xb000000000d33a13' 
(
	0   CoreFoundation                      0x0000000186d461d8  + 148
	1   libobjc.A.dylib                     0x000000018578055c objc_exception_throw + 56
	2   CoreFoundation                      0x0000000186d4d278  + 0
	3   CoreFoundation                      0x0000000186d4a278  + 916
	4   CoreFoundation                      0x0000000186c4459c _CF_forwarding_prep_0 + 92
	5   SwiftLive                           0x000000010023cb50 -[FLChatRoomInfoView stringRect:fontSize:constraintWidth:constraintHeight:] + 288
	6   SwiftLive                           0x00000001002354b0 -[FLChatRoomInfoView updateUIWithAnchor:liveRoomInfo:isFollow:] + 2736
	7   SwiftLive                           0x00000001001e1cd0 -[FLLiveMainInterfaceViewController setupContentView] + 3844
	8   SwiftLive                           0x00000001001dfe60 -[FLLiveMainInterfaceViewController setupUI] + 2708
	9   SwiftLive                           0x00000001001d8be0 -[FLLiveMainInterfaceViewController viewDidLoad] + 372
	10  UIKit                               0x000000018cba10b0  + 1056
	11  UIKit                               0x000000018cbb8c44  + 132
	12  UIKit                               0x000000018cd41190  + 1136
	13  UIKit                               0x000000018cc59858  + 676
	14  UIKit                               0x000000018cc594c0  + 64
	15  UIKit                               0x000000018cc59424  + 188
	16  UIKit                               0x000000018cb9e220  + 1196
	17  QuartzCore                          0x000000018a05e188  + 148
	18  QuartzCore                          0x000000018a052e64  + 292
	19  QuartzCore                          0x000000018a052d24  + 32
	20  QuartzCore                          0x0000000189fcf7ec  + 252
	21  QuartzCore                          0x0000000189ff6c58  + 512
	22  QuartzCore                          0x0000000189ff7678  + 120
	23  CoreFoundation                      0x0000000186cf37dc  + 32
	24  CoreFoundation                      0x0000000186cf140c  + 372
	25  CoreFoundation                      0x0000000186cf189c  + 1024
	26  CoreFoundation                      0x0000000186c20048 CFRunLoopRunSpecific + 444
	27  GraphicsServices                    0x00000001886a6198 GSEventRunModal + 180
	28  UIKit                               0x000000018cc0c2fc  + 684
	29  UIKit                               0x000000018cc07034 UIApplicationMain + 208
	30  SwiftLive                           0x000000010038e380 main + 312
	31  libdyld.dylib                       0x0000000185c045b8  + 4
)

boundingRectWithSize:options:attributes:context:

是计算字符串宽度的方法,而后台传过来的是nsnumber类型的,所以出错了,你没看错,我每天都在出错中度过


17、在 UIScrollView上面添加了一个View,点击View的时候,页面上滑了一下,测试过来提bug,emmmm,可是宝宝看了层级关系,没有可点击的东西啊,QAQ
       师父快来救我:

关于scrollView点击状态栏列表回到顶部的说明,想要禁用掉此功能将scrollsToTop属性设置为NO即可。


18、去除cell的点击后的选中背景:

方法一:自定义cell里面:

- (void)awakeFromNib {
    [super awakeFromNib];

    self.selectionStyle = UITableViewCellSelectionStyleNone;
}
方法二: 设置tableView的allowsSelection属性   注意:属性为NO的时候   tableView的代理方法: 

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 就不会执行 ,所以如果需要有cell点击事件的  不要用此方法

tableView.allowsSelection = NO; 

方法三:更改cell属性selectedBackgroundView 的背景色

我们选中cell时有灰色效果就是因为selectedBackgroundView这个家伙,所以,我们可以通过设置改View的背景色来改变选中颜色

self.selectedBackgroundView = [[UIView alloc] initWithFrame:cell.frame];  
self.selectedBackgroundView.backgroundColor = [UIColor redColor]; 

注意点:

1, 在storyboard设置tableView属性的时候   如果这样设置   selection: NoSelection   

 会导致点击cell的时候没反应  不会调用                                         didSelectRowAtIndexPath 方法  

 要想有点击方法应设置成                                                                 selection: SingleSelection


19、-[__NSCFNumber length]: unrecognized selector sent to instance 0xb000000000000033

2018-01-18 18:17:17.217 SwiftLive[1168:493865] : [BLYLog]  Trapped uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFNumber length]: unrecognized selector sent to instance 0xb000000000000033' 
(
	0   CoreFoundation                      0x00000001818a2ff8  + 148
	1   libobjc.A.dylib                     0x0000000180304538 objc_exception_throw + 56
	2   CoreFoundation                      0x00000001818a9ef4  + 0
	3   CoreFoundation                      0x00000001818a6f54  + 916
	4   CoreFoundation                      0x00000001817a2d4c _CF_forwarding_prep_0 + 92
	5   UIKit                               0x00000001879de58c  + 108
	6   UIKit                               0x00000001879de484  + 124
	7   UIKit                               0x0000000187ad29c0  + 272
	8   UIKit                               0x0000000187ad2704  + 52
	9   UIKit                               0x0000000187ad2230  + 488
	10  UIKit                               0x0000000188335ca0  + 112
	11  UIKit                               0x000000018833492c  + 192
	12  UIKit                               0x0000000188334c74  + 624
	13  UIKit                               0x0000000188334bfc  + 504
	14  UIKit                               0x0000000188334bfc  + 504
	15  UIKit                               0x0000000188334bfc  + 504
	16  UIKit                               0x0000000188334bfc  + 504
	17  UIKit                               0x0000000188334bfc  + 504
	18  UIKit                               0x0000000188334bfc  + 504
	19  UIKit                               0x0000000188334bfc  + 504
	20  Foundation                          0x00000001822dca7c  + 168
	21  UIKit                               0x0000000188335410  + 88
	22  UIKit                               0x0000000188334340  + 116
	23  UIKit                               0x0000000188335024  + 164
	24  UIKit                               0x0000000188336070  + 432
	25  UIKit                               0x00000001879e596c  + 892
	26  SwiftLive                           0x000000010022f88c __69-[FLLiveMainInterfaceViewController showDialogWithUserInfo:withType:]_block_invoke.1225 + 84
	27  UIKit                               0x0000000187a093dc  + 644
	28  UIKit                               0x0000000187b4da24  + 100
	29  SwiftLive                           0x000000010022f518 -[FLLiveMainInterfaceViewController showDialogWithUserInfo:withType:] + 620
	30  SwiftLive                           0x0000000100234a58 -[FLLiveMainInterfaceViewController chatMessageShowUserDetail:withType:] + 84
	31  SwiftLive                           0x00000001000f3cb4 -[FLChatMessageView getUserDetails:] + 1920
	32  SwiftLive                           0x00000001000f3ef0 -[FLChatMessageView showUserInfo:] + 444
	33  UIKit                               0x0000000187fa5d38  + 64
	34  UIKit                               0x0000000187fa956c  + 124
	35  UIKit                               0x0000000187b63470  + 252
	36  UIKit                               0x0000000187a05380  + 720
	37  UIKit                               0x0000000187f99810  + 988
	38  UIKit                               0x0000000187f993e0  + 404
	39  UIKit                               0x0000000187f9868c  + 268
	40  UIKit                               0x0000000187a0370c  + 3164
	41  UIKit                               0x00000001879d433c  + 340
	42  UIKit                               0x00000001881ce014  + 2400
	43  UIKit                               0x00000001881c8770  + 4268
	44  UIKit                               0x00000001881c8b9c  + 148
	45  CoreFoundation                      0x000000018185142c  + 24
	46  CoreFoundation                      0x0000000181850d9c  + 540
	47  CoreFoundation                      0x000000018184e9a8  + 744
	48  CoreFoundation                      0x000000018177eda4 CFRunLoopRunSpecific + 424
	49  GraphicsServices                    0x00000001831e8074 GSEventRunModal + 100
	50  UIKit                               0x0000000187a39058 UIApplicationMain + 208
	51  SwiftLive                           0x00000001003dc848 main + 312
	52  libdyld.dylib                       0x000000018078d59c  + 4
)


这个错误可能是因为 把整形变量直接赋值给NSString类型变量,没有进行转化。
我错在了,拿到后台的数据是Int类型,赋值给了我自己定义的String类型QAQ



你可能感兴趣的:(iOS,错误锦集)