【发布时间】:2012-06-02 03:17:41
【问题描述】:
我遇到了一个让我很头疼的奇怪问题。我正在使用 initWithObjects 初始化一个 NSArray 对象。我传递了 7 个对象,但紧接着,如果我记录数组的计数,我只有 3 个计数。还有其他人看到这个吗?我以前无数次使用这种方法没有问题,我看不出我做错了什么。代码如下:
-(DMORecipe *) saveRecipe:(NSNumber *)recipeID recipeTitle:(NSString *)title recipeDescription:(NSString *)description pictureFile:(NSString *)picFile preparationTime:(NSString *)prepTime cookingTime:(NSString *)cookTime ovenTemperature:(NSString *)ovenTemp {
NSArray *newRow = [[NSArray alloc] initWithObjects:recipeID,title, description, picFile, prepTime, cookTime, ovenTemp, nil];
NSLog(@"Before update, the number of args is %i", [newRow count]);
}
我是否在某个地方缺少了 type-o?您可以看到我将 7 个对象传递给数组初始化程序,但 NSLog 方法显示 [newRow count] = 3。
【问题讨论】:
-
nhahtdh 是对的。看看他下面的帖子。在方法
initWithObjects中,传递nil作为参数表示这是传入的最后一个对象。顺便说一句,我建议使用NSURL而不是NSString作为您的picFile 参数,作为NSURL存储路径数据时效率更高。查看此问题以获取有关 NSURL 和 NSStrings 的更多信息:stackoverflow.com/questions/7769219/…>
标签: objective-c nsarray