简体   繁体   English

丢了我的东西

[英]Lose my objects

I have UITableView with UISearchController filled with my custom objects. 我有UITableViewUISearchController充满我的自定义对象。 When i find some objects i call reloadData method. 当我找到一些对象时,我调用reloadData方法。 But i can't see any objects, because they are lost all the time. 但是我看不到任何物体,因为它们一直都在丢失。 I have groups, which translate into sections, each group contain objects, which translate into rows of section. 我有一些组,这些组可以转换成多个部分,每个组都包含一些对象,这些对象可以转换成多个部分的行。

There are some code and logs: 有一些代码和日志:

UISearchControllerDelegate method implementation: UISearchControllerDelegate方法的实现:

- (void)updateSearchResultsForSearchController:(UISearchController *)searchController
{
    // Searching

    // Put all found objects into findedObjects
    // Sort findedObjects to groups and put them into findedGroups

    findedObjects = searchResults;

    [findedGroups removeAllObjects];

    for (InfoGroup *buffGroup in groups)
    {
        InfoGroup *newGroup = [InfoGroup groupWithName:buffGroup.groupName andObjects:nil isMainGroup:buffGroup.mainGroup];
        newGroup.groupImageName = buffGroup.groupImageName;
        newGroup.groupPeoples = buffGroup.groupPeoples;

        BOOL flag = NO;

        for (InfoObject *obj in findedObjects) //sort objects
        {
            if ([obj.objectGroup.groupName isEqualToString:newGroup.groupName])
            {
                [newGroup.groupObjects addObject:obj];
//                obj.objectGroup = newGroup;
                NSLog(@"count of groupObjects: %li",[newGroup.groupObjects count]);
                flag = YES;
            }
        }

        if (flag) // if new group have more than 0 objects, put her in array
        {
            [findedGroups addObject:newGroup];
        }
    }

    NSLog(@"found %li groups and summary %li objects", [findedGroups count],[findedObjects count]);

    [self.tableView reloadData];
}

UITableView data source methods UITableView数据源方法

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    NSInteger count = ([findedGroups count] > 0) ? [findedGroups count] : [groups count];

    NSLog(@"number of sections: %li", count);

    return count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    NSInteger count = ([findedGroups count] > 0) ? [[findedGroups[section] groupObjects] count] : [[groups[section] groupObjects] count];

    NSLog(@"number of rows: %li in section: %li", count, section);

    return count;
}

There are very interesting logs (while typing something in search field, cleaned): 有非常有趣的日志(在搜索字段中键入内容时,已清除):

found 2 groups and summary 5 objects <----- 5 objects
number of sections: 2 <----- HERE TWO
number of rows: 0 in section: 1 <----- here 0 objects
number of rows: 0 in section: 0 <----- here 0 too

found 1 groups and summary 1 objects
number of sections: 1
number of rows: 0 in section: 0

found 1 groups and summary 1 objects
number of sections: 1
number of rows: 0 in section: 0

So, i lose my objects somewhere between numberOfSectionsInTableView and numberOfRowsInSection . 因此,我在numberOfSectionsInTableViewnumberOfRowsInSection之间的某个位置丢失了对象。

Any suggestions? 有什么建议么? May be i missing something, but i can't find what. 可能是我缺少了一些东西,但是我找不到。

Sorry for anxiety. 对不起,焦虑。 Really stupid mistake waste hours of time. 真正愚蠢的错误浪费时间。

Just for mark post as solved 仅用于标记发布已解决

I solve the problem. 我解决了问题。 Because i put nil here 因为我在这里放零

InfoGroup *newGroup = [InfoGroup groupWithName:buffGroup.groupName andObjects:nil isMainGroup:buffGroup.mainGroup];
groupObjects array was not initialized.

So i'm just update method for that case: 所以我只是针对这种情况的更新方法:

+(instancetype)groupWithName:(NSString*)initialName andObjects:(NSMutableArray*)initialObjects isMainGroup:(BOOL)initialMain
{
    if (initialObjects)
    {
        [ig setGroupObjects:initialObjects];
    } else
    {
        ig.groupObjects = [NSMutableArray array];
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 NSManagedObjectContext保存似乎丢失了对象 - NSManagedObjectContext save appearing to lose objects 更改Ios的视图后,我失去了蓝牙连接 - I lose my bluetooth connection after changing view on Ios 使用 popToRootViewController 时,我丢失了导航栏 - When using popToRootViewController I lose my navigation bar 如果我在 iOS / Google Play 商店更新我的 Unity 游戏,我的用户会丢失他们现有的数据吗? - If I update my Unity game on the iOS / Google Play stores, will my users lose their existing data? 为什么在重启iOS模拟器时,我的plist变为二进制并丢失其数据 - Why when restarting iOS Simulator my plist becomes binary and lose its data 为什么我的 UITableView 在异步重新加载数据期间滚动时会失去流动性? - Why does my UITableView lose it's fluidity when I scroll during an asynchronous reload data? 使视图控制器成为新的详细信息视图控制器时,我无法访问IBOutlets - I lose access to my IBOutlets when making view controller new detail view controller 我的NSMutablearray是否添加对象,而我的NSLog是否在数组中添加了正确数量的对象? - Is my NSMutablearray adding the objects and my NSLog the correct number of objects in the array? 为什么我的对象发生意外变化? - Why are my objects changing unexpectedly? 将我在Map上的对象与数据连接 - connecting my objects on Map with data
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM