我正在尝试从 sqlite 数据库中提取文章并将它们显示在表格视图中。选择表格单元格时,应该与源页面一起显示 web 视图。到目前为止,除了显示源页面外,一切正常。这是我的一些代码:
(在初始化方法中)
articles = [[NSMutableArray alloc] init];
webPages = [[NSMutableArray alloc] init];
int arrayCount = data.count;
int i;
for (i = 0; i < arrayCount; i++) {
Item *currentItem = [[Item alloc] init];
currentItem = [data objectAtIndex:i];
[articles insertObject:currentItem.itemTitle atIndex:i];
[webPages insertObject:currentItem.detailURL atIndex:i];
NSLog(@"%@", [webPages objectAtIndex:i]);
//[webPages insertObject:@"http://onlyfans.cstv.com/schools/tul/sports/w-volley/recaps/102812aaa.html" atIndex:i]; -- >this works fine. i got this url from the nslog above.
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
WebViewController *webViewController = [[WebViewController alloc] initWithString:[webPages objectAtIndex:
indexPath.row]];
[self.parentViewController.navigationController pushViewController:webViewController animated:YES];
这是从数据库中获取有关每篇文章的信息的方法...
if(sqlite3_open([self.databasePath UTF8String], &database) == SQLITE_OK) {
NSLog(@"DataLoader::readItemsFromDatabase : database open successful!");
sqlite3_stmt *compiledStatement;
if(sqlite3_prepare_v2(database, [sqlStatement UTF8String], -1, &compiledStatement, NULL) == SQLITE_OK) {
NSLog(@"select ok.");
// Loop through the results and add them to the feeds array
while(sqlite3_step(compiledStatement) == SQLITE_ROW) {
// Read the data from the result row
int lineItemsID=sqlite3_column_int(compiledStatement, 0);
NSLog(@"DataLoader::readItemsFromDatabase : source id [%i]", lineItemsID);
NSString *aItemTitle = @" ";
NSString *aPublishDate = @" ";
NSString *aDetailURL = @" ";
NSString *aDesc = @" ";
if (sqlite3_column_text(compiledStatement, 2) != nil) {
aItemTitle=[NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 2)];
NSLog(@"DataLoader::readItemsFromDatabase :row>>id %i, itemTitle %s",lineItemsID,sqlite3_column_text(compiledStatement, 2));
// NSLog(@"DataLoader::readSourcesFromDatabase :row>>id %i, name %s",lineItemsID,aItemTitleL);
}
if (sqlite3_column_text(compiledStatement, 3) != nil) {
aPublishDate=[NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 3)];
NSLog(@"DataLoader::readItemsFromDatabase :row>>id %i, publishDate %s",lineItemsID,sqlite3_column_text(compiledStatement, 3));
}
if (sqlite3_column_text(compiledStatement, 4) != nil) {
aDetailURL=[NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 4)];
NSLog(@"DataLoader::readItemsFromDatabase :row>>id %i, detail URL %s",lineItemsID,sqlite3_column_text(compiledStatement, 4));
}
if (sqlite3_column_text(compiledStatement, 5) != nil) {
aDesc=[NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 5)];
NSLog(@"DataLoader::readItemsFromDatabase :row>>id %i, desc %s",lineItemsID,sqlite3_column_text(compiledStatement, 5));
}
Item *item= [[Item alloc] init];
item.itemTitle = aItemTitle;
item.publishDate = aPublishDate;
item.detailURL = aDetailURL;
item.desc = aDesc;
我不明白为什么我可以从 currentItem 对象中获取 URL 字符串并将其显示在 NSLog 中,但我不能直接使用它来打开 webview。有人遇到过这种问题吗?
谢谢你的帮助!
稀树草原