OStack程序员社区-中国程序员成长平台

标题: ios - Objective-C 检查 NSMutableArray 中是否存在项目 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 07:20
标题: ios - Objective-C 检查 NSMutableArray 中是否存在项目

我这里有这段代码:

for (int i = 0; i<[taskData count]; i++)
    {
        for (int j=0; j<[allJobTaskArray count]; j++)
        {
            NSLog(@"%d", i);
            NSLog(@"%d", j);
            PunchListDataCell *pldCell = [[[PunchListDataCell alloc]init] autorelease];
            pldCell.stringData= [self reverseStringDate:[[[allJobTaskArray objectAtIndex:j] objectAtIndex:i] substringToIndex:10]];
            pldCell.cellSelected = NO;
            [punchListData addObject:pldCell];
        }

    }

现在让我解释一下:

我尝试了以下方法:

if([[allJobTaskArray objectAtIndex:j] objectAtIndex:i] == [NSNull null]){
                pldCell.stringData = @"";
            }else{
                pldCell.stringData= [self reverseStringDate:[[[allJobTaskArray objectAtIndex:j] objectAtIndex:i] substringToIndex:10]];
            }



Best Answer-推荐答案


总而言之,它应该看起来像 -

for (int i = 0; i<[taskData count]; i++)
    {
        for (int j=0; j<[allJobTaskArray count]; j++)
        {
            NSLog(@"%d", i);
            NSLog(@"%d", j);


            PunchListDataCell *pldCell = [[[PunchListDataCell alloc]init] autorelease];
            if ([[allJobTaskArray objectAtIndex:j] count] > i) {                    
                pldCell.stringData= [self reverseStringDate:[[[allJobTaskArray objectAtIndex:j] objectAtIndex:i] substringToIndex:10]];
            } else {
                pldCell.stringData = @"";
            }

            pldCell.cellSelected = NO;
            [punchListData addObject:pldCell];
        }
    }

关于ios - Objective-C 检查 NSMutableArray 中是否存在项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30316157/






欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) Powered by Discuz! X3.4