0

記事を sqlite データベースから取り出してテーブル ビューに表示しようとしています。テーブル セルが選択されると、Web ビューがソース ページと共に表示されるはずです。これまでのところ、ソース ページの表示以外はすべて機能しています。これが私のコードの一部です:

(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 に表示できる理由がわかりませんが、それを直接使用して Web ビューを開くことはできません。誰もこの種の問題を抱えたことがありますか?

ご協力いただきありがとうございます!

サバンナ

4

1 に答える 1

0

nslog を試してください:

[webPages objectAtIndex:indexPath.row];

didSelectRowAtIndexPath で、それが何を返すかを確認します。

また、webPages を宣言する場所にも問題がある可能性があります。使用してみてください:

@property(nonatomic, strong) NSMutableArray *webPages;

合成する:

webPages = _webPages;

viewDidLoad で webPages を初期化してみてください:

self.webPages = [[NSMutableArray alloc] init];
于 2012-10-31T19:15:56.687 に答える