我这里有这段代码:
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];
}
}
现在让我解释一下:
pldCell.stringData= [self reverseStringDate:[[[allJobTaskArray objectAtIndex:j] objectAtIndex:i] substringToIndex:10]];
when j
是 6 而 i
是 36 简单,因为在 allJobTaskArray
objectAtIndex: 6 objectAtIndex: 36 不存在。[__NSCFArray objectAtIndex:]: index (36) beyond bounds (36)
pldCell
应该等于 @""
;
我尝试了以下方法:
if([[allJobTaskArray objectAtIndex:j] objectAtIndex:i] == [NSNull null]){
pldCell.stringData = @"";
}else{
pldCell.stringData= [self reverseStringDate:[[[allJobTaskArray objectAtIndex:j] objectAtIndex:i] substringToIndex:10]];
}
总而言之,它应该看起来像 -
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 |