1、今天遇到一個(gè)問題:tableview中要?jiǎng)h除某一行,所有同時(shí)要?jiǎng)h除數(shù)據(jù)源mutable array 中的某條數(shù)據(jù),剛開始我是這樣做的:
for (PZHelper *helper in helpers) {
if ([helper.groupId isEqualToString:group.groupId]) {
[helperArr removeObject:helper];
}
}
發(fā)現(xiàn)刪除最后一行行(xing),刪除中間的行總是報(bào)錯(cuò):*** Terminating app due to uncaught exception 'NSGenericException', reason: '*** Collection <__NSArrayM: 0x7fafc948bc50> was mutated while being enumerated.'
后來找到array 的block方法,采用此方法可以比for循環(huán)查找快20%左右,所有以后再遇到這種問題就要注意了。
如下:
[helpers enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
PZHelper *helper = obj;
if ([helper.groupId isEqualToString:group.groupId]) {
*stop = YES;
if (*stop == YES) {
[helpers removeObjectAtIndex:idx];
}
}
}];
2、在通過代碼調(diào)整AutoLayout約束時(shí),出現(xiàn)了約束變更后沒有及時(shí)刷新的問題,原來要在調(diào)整約束代碼后加上 [self.view layoutIfNeeded];
例如:
self.customContentViewLCHeight.constant = 84;
[self.view layoutIfNeeded];
3、在做聊天界面時(shí),遇到一個(gè)問題:氣泡里面有一個(gè)textView,當(dāng)tableView多選時(shí)textView背景為灰色,看起來很不爽,研究半天,發(fā)現(xiàn)需要做如下設(shè)置
例如:
self.tableView.allowsMultipleSelection = YES;
self.tableView.allowsMultipleSelectionDuringEditing = YES;
同時(shí),還要考慮到多選時(shí)cell中氣泡的點(diǎn)擊、長按事件此時(shí)不可用的問題,否則點(diǎn)擊會(huì)沖突。
5、今天又遇到一個(gè)奇怪的問題,在一個(gè)數(shù)組中遍歷另一個(gè)數(shù)組,當(dāng)他們的titile值一樣時(shí),將它從數(shù)組中移除,發(fā)現(xiàn)要移除的5個(gè)總是有最后兩個(gè)移除不了,研究了半天,終于找到解決方案:用一個(gè)數(shù)組存儲(chǔ)要?jiǎng)h除的數(shù)據(jù),然后在for循環(huán)下面執(zhí)行刪除。我的錯(cuò)誤就在于在兩個(gè)遍歷里面做刪除操作。
NSMutableArray *removeObjs = [NSMutableArray array];
for (NSInteger i = 0 ; i < mutableLocationArr.count; i++) {
NSDictionary *item = mutableLocationArr[i];
for (NSDictionary *dict in locationDeleteData) {
// NSLog(@"dict %@", dict[@"title"]);
NSString *title1 = [dict objectForKey:@"title"];
if ([item[@"title"] isEqualToString:title1]) {
NSLog(@"title %@", item[@"title"]);
[removeObjs addObject:item];
// [mutableLocationArr removeObject:item];
}
}
}
[mutableLocationArr removeObjectsInArray:removeObjs];