我試圖從SQLite數據庫中拉出文章並將它們顯示在表格視圖中。選擇表格單元格時,應該在源頁面中顯示Web視圖。到目前爲止,除了顯示源頁面之外,所有內容都可以工下面是我的一些代碼:UIWebView將不會顯示UTF8String
(在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。有人有過這種問題嗎?
感謝您的幫助!
大草原
你需要表現出更多的(相關)的代碼,從此它的很難說出了什麼問題。 – 2012-10-31 19:13:16
我增加了一些東西,也許它會更有幫助... –