setText:已弃用

时间:2011-08-07 21:04:30

标签: ios xcode4 deprecated settext

我试着学习如何使用sql数据源,我在apple的示例中找到了一个示例名称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/

我在app delegate中有其他警告

// 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

enter image description here

/ 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;

}

谢谢你有答案。

2 个答案:

答案 0 :(得分:3)

cell.textLabel.text = animal.name;

自iOS 3.0起,您是如何在单元格中设置文本的。

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

答案 1 :(得分:1)

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

  

细胞的文字。 (在iOS 3.0中不推荐使用。使用textLabel和   而不是detailTextLabel属性。)

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