Iphone NSDictionary:第二个对象必须是非nil

Iphone NSDictionary:第二个对象必须是非nil,iphone,nsdictionary,Iphone,Nsdictionary,经过大量的搜索,我找到了各种各样的解决方案,但在我的情况下没有任何效果。在NSDictionary中绑定数据时出现此错误。崩溃日志包括: Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+[NSDictionary dictionaryWithObjectsAndKeys:]: second object of each pair must be non-nil. Or,

经过大量的搜索,我找到了各种各样的解决方案,但在我的情况下没有任何效果。在NSDictionary中绑定数据时出现此错误。崩溃日志包括:

    Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+[NSDictionary dictionaryWithObjectsAndKeys:]: second object of each pair must be non-nil.  Or, did you forget to nil-terminate your parameter list?'
*** First throw call stack:
代码:

 while(sqlite3_step(select_statement) == SQLITE_ROW)

    {

//            const char* recipeID = (const char*)sqlite3_column_text(select_statement, 1);
//            const char* recipename = (const char*)sqlite3_column_text(select_statement, 0);
//            const char* recipepicname = (const char*)sqlite3_column_text(select_statement, 3);
//            const char* chapterid = (const char*)sqlite3_column_text(select_statement, 4);
//            const char* recipedesc = (const char*)sqlite3_column_text(select_statement, 2);
//            
//            
//             srtRecipestepId = recipeID == NULL ? nil : [[NSString alloc]initWithUTF8String:recipeID];
//             strRecipeName = recipename == NULL ? nil : [[NSString alloc]initWithUTF8String:recipename];
//             NSString *recipePicName = recipepicname == NULL ? nil : [[NSString alloc]initWithUTF8String:recipepicname];
//             strRecipeIntro = recipedesc == NULL ? nil : [[NSString alloc]initWithUTF8String:recipedesc];
//             NSString *strchapterId = chapterid == NULL ? nil : [[NSString alloc]initWithUTF8String:chapterid];

            srtRecipestepId=[NSString stringWithUTF8String:(char *)sqlite3_column_text(select_statement, 1)];
            strRecipeName=[NSString stringWithUTF8String:(char *)sqlite3_column_text(select_statement, 0)];
           // RecipestepPics = [[NSData alloc] initWithBytes:sqlite3_column_blob(select_statement, 3) length:sqlite3_column_bytes(select_statement, 3)];
           NSString *recipePicName = [NSString stringWithUTF8String:(char *)sqlite3_column_text(select_statement, 3)];
            strRecipeIntro = [NSString stringWithUTF8String:(char *)sqlite3_column_text(select_statement, 2)];
            NSString *strchapterId = [NSString stringWithUTF8String:(char *)sqlite3_column_text(select_statement, 4)];

            [arrreturnRecipefinder addObject:[NSDictionary dictionaryWithObjectsAndKeys:srtRecipestepId,@"RecipestepId",strRecipeName,@"RecipeName",recipePicName,@"RecipestepPics",strRecipeIntro,@"RecipeIntro",strchapterId,@"RecipeChapterId"]];


        }

从错误消息中:

。。。或者,您是否忘记了零终止参数列表

是的,你做到了!应该是

[NSDictionary dictionaryWithObjectsAndKeys:srtRecipestepId, @"RecipestepId",
                    strRecipeName, @"RecipeName",
                    recipePicName, @"RecipestepPics",
                   strRecipeIntro, @"RecipeIntro",
                     strchapterId, @"RecipeChapterId",
                     nil]   // <-- nil-termination of variable argument list
[NSDictionary Dictionary WithObjectsAndKeys:srtRecipestepId,@“RecipestepId”,
strRecipeName,@“RecipeName”,
RecipePics名称@“RecipestepPics”,
strRecipeIntro,@“RecipeIntro”,
strchapterId,@“RecipeChapterId”,

nil]/您没有将
nil
参数添加到字典的结尾。因为
nil
用作标记“参数结尾”列表的“哨兵”

 [arrreturnRecipefinder addObject:[NSDictionary dictionaryWithObjectsAndKeys:srtRecipestepId,@"RecipestepId",strRecipeName,@"RecipeName",recipePicName,@"RecipestepPics",strRecipeIntro,@"RecipeIntro",strchapterId,@"RecipeChapterId", nil]];