1

我试图学习如何使用 sql 数据源,我在苹果的示例中找到了一个示例名称 SQLiteTutorial 太糟糕了,苹果没有更新他们的示例,所以当我打开苹果示例文件时,我收到了许多不推荐使用的警告...... .

在这种情况下,代码是

// Set up the cell
    SQLiteTutorialAppDelegate *appDelegate = (SQLiteTutorialAppDelegate *)[[UIApplication sharedApplication] delegate];
    Animal *animal = (Animal *)[appDelegate.animals objectAtIndex:indexPath.row];

    [cell setText:animal.name];
    return cell;  

Xcode 说我不推荐使用 setText,但我没有找到解决方法。

我正在处理的教程在这里:http ://dblog.com.au/iphone-development-tutorials/iphone-sdk-tutorial-reading-data-from-a-sqlite-database/

我在应用程序委托中有其他警告

// Execute the "checkAndCreateDatabase" function
    [self checkAndCreateDatabase];

    // Query the database for all animal records and construct the "animals" array
    [self readAnimalsFromDatabase];

    // Configure and show the window
    [window addSubview:[navigationController view]];
    [window makeKeyAndVisible];
}

Xcode 告诉我 SQLiteTutorialAppDelegate 可能不会响应 checkAndCreateDatabase 和 readAnimalsFromDatabase

和 RootViewController 中的最后一件事,实例方法 initWithData:cache not found

在此处输入图像描述

/ Load the animals image into a NSData boject and then assign it to the UIImageView
    NSData *imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:[animal imageURL]]];




    UIImage *animalImage = [[UIImage alloc] initWithData:imageData cache:YES];
    self.animalView.animalImage.image = animalImage;

}

谢谢,如果你有答案。

4

2 回答 2

3
cell.textLabel.text = animal.name;

是自 iOS 3.0 以来您在单元格中设置文本的方式。

不知道其他警告,因为它们与您未发布的代码有关。从这样的旧代码中学习不是一个好主意,您可能应该找到一些更新的东西:)

于 2011-08-07T21:07:41.230 回答
1

文档始终是寻找如何替换已弃用方法的良好开端:

单元格的文本。(在 iOS 3.0 中已弃用。请改用 textLabel 和 detailTextLabel 属性。)

至于您的其他警告,您可能忘记在头文件中声明readAnimalsFromDatabaseandcheckAndCreateDatabase方法。

于 2011-08-07T21:13:32.663 回答