我能够获得书籍的标题列表(tableview),当我选择书籍时,我想推进书籍细节的新视图。我是在titleView类'didSelectRow'还是在DetailView类'viewWillAppear'中执行此操作,如果是这样,我必须准备什么来获取语句,3或contentInfo?
数据库类
(NSArray *) itemsByAuthorID:(NSInteger)authorID {
NSMutableArray *retval = [[NSMutableArray alloc] init];
NSString *query;
code....
query = [NSString stringWithFormat:@"select * from books where books.author_id = '%i'", authorID];
}
code...
sqlite3_stmt *statement;
if (sqlite3_prepare_v2(_database, [query UTF8String], -1, &statement, nil) == SQLITE_OK){
while (sqlite3_step(statement) == SQLITE_ROW) {
int itemID = sqlite3_column_int(statement, 0);
int authorID = sqlite3_column_int(statement, 1);
char *nameChars = (char *) sqlite3_column_text(statement, 2);
char *itemContent = (char *) sqlite3_column_text(statement, 3);
NSString *contentTitle = [[NSString alloc] initWithUTF8String:nameChars];
NSString *contentInfo = [[NSString alloc] initWithUTF8String:itemContent];
Item *info = [[Item alloc] initWithItemID:itemID authorID:authorID contentTitle:(NSString *)contentTitle contentInfo:contentInfo];
[retval addObject:info];
}
sqlite3_finalize(statement);
}
return retval;
答案 0 :(得分:0)
您可以为Book中的所有书籍创建Book的私有类,并从数据库中检索数据。
然后在调用didSelectRow之后,只将Book的对象作为参数传递并在详细信息视图中显示详细信息。