私は my から行を読み取ってからSQLite DB
、データをに変換してJSON
に入れようとしていNSMutableArray
ます。次に、配列をループして、データを my に出力しますtable view
。
これは、データをロードするために私が行うことですSQLite
:
entries = [[NSMutableArray alloc] init];
NSString *sql = [NSString stringWithFormat:@"SELECT * FROM chatHistory GROUP BY channelID ORDER BY time DESC"];
sqlite3_stmt *statement;
if(sqlite3_prepare_v2([box db], [sql UTF8String], -1, &statement, nil) == SQLITE_OK) {
while(sqlite3_step(statement) == SQLITE_ROW) {
char *field1 = (char *) sqlite3_column_text(statement, 0);
NSString *channelID = [[NSString alloc] initWithUTF8String:field1];
char *field2 = (char *) sqlite3_column_text(statement, 0);
NSString *sender = [[NSString alloc] initWithUTF8String:field2];
char *field3 = (char *) sqlite3_column_text(statement, 0);
NSString *message = [[NSString alloc] initWithUTF8String:field3];
char *field4 = (char *) sqlite3_column_text(statement, 0);
NSString *recipient = [[NSString alloc] initWithUTF8String:field4];
char *field5 = (char *) sqlite3_column_text(statement, 0);
NSString *time = [[NSString alloc] initWithUTF8String:field5];
NSString *messageArray = [[NSString alloc] initWithFormat:@"[{ \"channelID\":\"%@\", \"sender\":\"%@\", \"message\":\"%@\", \"recipient\":\"%@\", \"time\":\"%@\"}]", channelID, sender, message, recipient, time];
// Convert to JSON object:
NSArray *jsonObject = [NSJSONSerialization JSONObjectWithData:[messageArray dataUsingEncoding:NSUTF8StringEncoding]
options:0 error:NULL];
[entries addObject:jsonObject];
今ここに私がそれを私のに追加しようとする方法がありますtable view
:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"ConvCell";
ConvCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[ConvCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
NSArray *tableData = [self.entries valueForKey:@"message"];
NSLog(@"Message=%@", tableData);
cell.visitorName.text = (NSString *) [self.entries objectAtIndex:indexPath.row]; // This trows an error
cell.visitorAvatar.image = [UIImage imageNamed:@"hello.png"];
cell.messageTime.text = @"19.10";
return cell;
}
エラーは次のとおりです。
exception 'NSInvalidArgumentException', reason: '-[__NSCFArray length]: unrecognized selector sent to instance 0xa0cfc40'
私が間違っていることはありますか?