0
if (sqlite3_prepare_v2(dbHandlerPointerNote ,selectQuery , -1, &prepareStmtNote, NULL) == SQLITE_OK)                     {
            while (sqlite3_step(prepareStmtNote) == SQLITE_ROW)

        {
            NSString *noteName = [[NSString alloc]initWithUTF8String:(const char *) sqlite3_column_text(prepareStmtNote, 0)];
            [_notesArray addObject:noteName];
            int noteid =sqlite3_column_int(prepareStmtNote, 1);
            [_noteidArray  addObject:[NSString stringWithFormat:@"%d",noteid]];
            NSString *noteDate = [[NSString alloc]initWithUTF8String:(const char *) sqlite3_column_text(prepareStmtNote,2)];
            [_notesDate addObject:noteDate];
            // arrObj is a mutable arr

        }
    }

note_id上記は、オブジェクトを配列に追加する方法です。

最後のオブジェクトを取得しようとしている方法は次のとおりです。

_savedNoteid1=[[_modleClass.noteidArray lastObject]intValue];

しかし、正しく動作していません。配列の最後のオブジェクトを取得するにはどうすればよいですか?

4

2 に答える 2

2

配列に最後に追加されたオブジェクトを取得したいのですが、どうすればよいのでしょうか。

-lastObjectNSArray(またはNSMutableArray)のインスタンスの最後のオブジェクトにアクセスするだけの場合は、次のメソッドを使用できます。

id item = [someArray lastObject];
于 2013-03-09T07:23:01.223 に答える
2

現在使用しているものは非常に近く、最後の部分(intValue)を削除するだけです。

_savedNoteid1=[_modleClass.noteidArray lastObject];
于 2013-03-09T07:26:01.337 に答える