我正在尝试从sqlite数据库中提取文章并将其显示在表格视图中。选择表格单元格时,应该与源页面一起显示webview。到目前为止,一切都有效,除了显示源页面。以下是我的一些代码:
(在init方法中)
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。有没有人遇到过这种问题?
感谢您的帮助!
大草原
答案 0 :(得分:0)
尝试使用nslog:
[webPages objectAtIndex:indexPath.row];
问题可能在于您声明webPages的位置。尝试使用:
@property(nonatomic, strong) NSMutableArray *webPages;
合成
webPages = _webPages;
并尝试在viewDidLoad中初始化webPages:
self.webPages = [[NSMutableArray alloc] init];