【iOS】crash收集

前言:主要记录iOS开发过程中常常遇到的crash,以及解决办法~

2. CALayer bounds contains NaN: [nan nan; 375 375]
出现这个问题原因(nan,nan,375,375) x,y is not a numer;比如crash代码如下:
[cc lang=’c’]
CGRect rect = CGRectZero;
rect.size.height = 375;
rect.size.width = 375;
rect.origin.x = NAN;
rect.origin.y = NAN;
playerLayer.frame = rect; // crash
// scrollView.contentSize = rect.size; // 没用到x,y不会crash
[/cc]
解决办法可以用isnan()来判断,如下:
[cc lang=’c’]
CGRect rect = CGRectZero;
rect.size.height = 375;
rect.size.width = 375;
rect.origin.x = NAN;
rect.origin.y = NAN;
if (isnan(frame.origin.x)) {
frame.origin.x = 0;
}
if (isnan(frame.origin.y)) {
frame.origin.y = 0;
}
playerLayer.frame = rect;
[/cc]

3. Invalid update: invalid number of rows in section
[cc lang=’c’]
Invalid update: invalid number of rows in section 0. The number of rows contained in an existing section after the update (24) must be equal to the number of rows contained in that section before the update (15), plus or minus the number of rows inserted or deleted from that section (0 inserted, 0 deleted) and plus or minus the number of rows moved into or out of that section (0 moved in, 0 moved out).
[/cc]
出现这个问题主要是数据源的问题,比如下面代码:
[cc lang=’c’]
loadData(){
// 改变了sectionArray ,如果及时reloadData,在下面代码中用到sectionArray就crash了
}

[_tableView beginUpdates];
// sectionArray
[_tableView endUpdates];

– (NSInteger)tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)section
{
return _musicDataSource.count; // crash
}
[/cc]

4. *** Collection was mutated while being enumerated.
    *** Collection was mutated while being enumerated.
出现这个问题,就是在便利值时,增,删,改这些值;比如crash代码:
[cc lang=’c’]
NSMutableArray *domainsArray = @[@”cxck.com”, @”ltbg.com”, @”return.love”].mutableCopy;
for (NSString *str in domainsArray) {
domainsArray[2] = @”bengzha.com”; // crash
[domainsArray removeObject:str]; // crash
[domainsArray addObject:@”zhece.com”]; // crash
}
[/cc]
解决这些问题代码:
[cc lang=’c’]
NSMutableArray *domainsArray = @[@”cxck.com”, @”ltbg.com”, @”return.love”].mutableCopy;
NSArray *tempArr = domainsArray.copy;
for (NSString *str in tempArr) {
[domainsArray removeObject:str];
}

// or
[domainsArray enumerateObjectsUsingBlock:^(NSString * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
if ([obj isEqualToString:@”cxck.com”]) {
*stop = YES;
[domainsArray removeObject:obj];
}
}];
[/cc]

5.在iPhone上导致crash的图片和视频(点击下载)

// 更新中…

发表回复

电子邮件地址不会被公开。 必填项已用*标注