Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios Objective-C从包含indexpath的NSArray中删除对象_Ios_Objective C - Fatal编程技术网

Ios Objective-C从包含indexpath的NSArray中删除对象

Ios Objective-C从包含indexpath的NSArray中删除对象,ios,objective-c,Ios,Objective C,我有一个包含nsindepath的数组,我想删除所有具有相同indepath.Row的对象。我当前的代码有一些问题,不是所有具有相同行的对象都被删除。 我的代码是: rowValue=(int)btn.tag; for (int i=0; i<[SingletonClass singleton].arraySubMenuItems.count; i++) { NSIndexPath * Path = [[SingletonClass singleton].arraySubMen

我有一个包含nsindepath的数组,我想删除所有具有相同indepath.Row的对象。我当前的代码有一些问题,不是所有具有相同行的对象都被删除。 我的代码是:

 rowValue=(int)btn.tag;
 for (int i=0; i<[SingletonClass singleton].arraySubMenuItems.count; i++)
{
    NSIndexPath * Path = [[SingletonClass singleton].arraySubMenuItems objectAtIndex:i];
    int section = (int) Path.section;
    if (section == rowValue)
    {

        NSIndexPath *indexPath = [[SingletonClass singleton].arraySubMenuItems objectAtIndex:i];
        [[SingletonClass singleton].arraySubMenuItems removeObjectAtIndex:i];

    }
}
rowValue=(int)btn.tag;

对于(inti=0;i您可以删除如下对象

rowValue=(int)btn.tag;
NSMutableArray *arrTemp = [NSMutableArray new];
for (int i=0; i<[SingletonClass singleton].arraySubMenuItems.count; i++)
{
    NSIndexPath * Path = [[SingletonClass singleton].arraySubMenuItems objectAtIndex:i];
    int section = (int) Path.section;
    if (section == rowValue)
    {
        [arrTemp addObject:[[SingletonClass singleton].arraySubMenuItems objectAtIndex:i]];
    }
}
[[SingletonClass singleton].arraySubMenuItems removeObjectsInArray:arrTemp];
rowValue=(int)btn.tag;
NSMUTABLEARRY*arrTemp=[NSMUTABLEARRY new];

对于(inti=0;i您可以删除如下对象

rowValue=(int)btn.tag;
NSMutableArray *arrTemp = [NSMutableArray new];
for (int i=0; i<[SingletonClass singleton].arraySubMenuItems.count; i++)
{
    NSIndexPath * Path = [[SingletonClass singleton].arraySubMenuItems objectAtIndex:i];
    int section = (int) Path.section;
    if (section == rowValue)
    {
        [arrTemp addObject:[[SingletonClass singleton].arraySubMenuItems objectAtIndex:i]];
    }
}
[[SingletonClass singleton].arraySubMenuItems removeObjectsInArray:arrTemp];
rowValue=(int)btn.tag;
NSMUTABLEARRY*arrTemp=[NSMUTABLEARRY new];
对于(int i=0;i
rowValue=(int)btn.tag;
int countItem=[SingletonClass singleton].arraySubMenuItems.count;
对于(int i=0;i
将您的计数存储在不同的变量中,并在该变量上运行循环,因为当您从indexpath中删除项目时,它会更改您的totalcount。

rowValue=(int)btn.tag;
int countItem=[SingletonClass singleton].arraySubMenuItems.count;
对于(int i=0;i

将您的计数存储在不同的变量中,并在该变量上运行循环,因为当您从indexpath中删除项目时,它会更改您的总计数。

您可以在indexset中获取要删除的项目的索引,并按索引删除项目。 我就是这么做的

 rowValue=(int)btn.tag;
        NSMutableIndexSet *indicesToRemove = [[NSMutableIndexSet alloc]init];
    for (int i=0; i<[SingletonClass singleton].arraySubMenuItems.count; i++)
    {
        NSIndexPath * Path = [[SingletonClass singleton].arraySubMenuItems objectAtIndex:i];
        int section = (int) Path.section;
        if (section == rowValue)
        {
        [indicesToRemove addIndex:i]
        }
    }
    [[SingletonClass singleton].arraySubMenuItems removeObjectsAtIndexes:indices];
rowValue=(int)btn.tag;
NSMutableIndexSet*指示删除=[[NSMutableIndexSet alloc]init];

对于(int i=0;i,您可以在索引集中获取要删除的项的索引,并按索引删除这些项。 我就是这么做的

 rowValue=(int)btn.tag;
        NSMutableIndexSet *indicesToRemove = [[NSMutableIndexSet alloc]init];
    for (int i=0; i<[SingletonClass singleton].arraySubMenuItems.count; i++)
    {
        NSIndexPath * Path = [[SingletonClass singleton].arraySubMenuItems objectAtIndex:i];
        int section = (int) Path.section;
        if (section == rowValue)
        {
        [indicesToRemove addIndex:i]
        }
    }
    [[SingletonClass singleton].arraySubMenuItems removeObjectsAtIndexes:indices];
rowValue=(int)btn.tag;
NSMutableIndexSet*指示删除=[[NSMutableIndexSet alloc]init];

for(int i=0;iYou正在迭代并同时修改数组(尤其是删除项)。是的,我知道。我该怎么办?您可以对每个对象使用,然后删除对象[[SingletonClass singleton]。arraySubMenuItems removeObject:indexPath];我可以知道你为什么要将行与节进行比较吗?它实际上不是一行。它只是一个节。我从按钮标记中获取一个行值。你正在迭代,同时修改数组(尤其是删除项)。是的,我知道。我该怎么办?你可以对每个行使用,然后删除对象[[SingletonClass singleton].arraySubMenuItems removeObject:indexPath];我可以知道为什么要将行与节进行比较吗?它实际上不是一行。它只是一个节。我正在从按钮标记获取一个行值。您保存了我:DGlad它帮助了:)您保存了我:DGlad它帮助了:)