iOS 开发中遇到的问题总结-不断更新

1、今天遇到一个问题:tableview中要删除某一行,所有同时要删除数据源mutable array 中的某条数据,刚开始我是这样做的:

        for (PZHelper *helper in helpers) {
            if ([helper.groupId isEqualToString:group.groupId]) {
                [helperArr removeObject:helper];
            }
        }

发现删除最后一行行(xing),删除中间的行总是报错:*** Terminating app due to uncaught exception 'NSGenericException', reason: '*** Collection <__NSArrayM: 0x7fafc948bc50> was mutated while being enumerated.'

后来找到array 的block方法,采用此方法可以比for循环查找快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、在通过代码调整AutoLayout约束时,出现了约束变更后没有及时刷新的问题,原来要在调整约束代码后加上 [self.view layoutIfNeeded];

例如:

self.customContentViewLCHeight.constant = 84;
[self.view layoutIfNeeded];

3、在做聊天界面时,遇到一个问题:气泡里面有一个textView,当tableView多选时textView背景为灰色,看起来很不爽,研究半天,发现需要做如下设置

例如:

self.tableView.allowsMultipleSelection = YES; 

self.tableView.allowsMultipleSelectionDuringEditing = YES;

同时,还要考虑到多选时cell中气泡的点击、长按事件此时不可用的问题,否则点击会冲突。

5、今天又遇到一个奇怪的问题,在一个数组中遍历另一个数组,当他们的titile值一样时,将它从数组中移除,发现要移除的5个总是有最后两个移除不了,研究了半天,终于找到解决方案:用一个数组存储要删除的数据,然后在for循环下面执行删除。我的错误就在于在两个遍历里面做删除操作。

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];

你可能感兴趣的:(iOS 开发中遇到的问题总结-不断更新)