2011-08-07 35 views
1

我試圖學習如何使用SQL數據源,我在蘋果示例中找到示例名稱SQLiteTutorial 什麼不好,蘋果沒有更新它們的樣本,所以當我打開蘋果示例文件時,已經在這種情況下,得到了許多過時的警告....setText:已棄用

代碼

// 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:找不到緩存

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; 

} 

感謝,如果你有一個答案。

回答

3
cell.textLabel.text = animal.name; 

從iOS 3.0開始,您是如何在單元格中設置文本的。

不知道其他的警告,因爲它們都涉及到代碼你沒有張貼。從這些舊的代碼中學習是不是一個好主意,你應該找到一些稍微新一點:)

+0

感謝您的回答,很明顯如此。在他們的回答中,很多人忘記了英語不是我的母語,而且我是初學者,有時候他們的答案對我來說是中國人。謝謝 – a3116b

1

documentation始終是一個良好的開端,尋找如何更換過時的方法:

的文本細胞。 (不推薦使用iOS中3.0。使用爲textLabel和 detailTextLabel屬性,而不是。)

至於你的其他的警告,你可能已經忘記了申報在頭文件中的readAnimalsFromDatabasecheckAndCreateDatabase方法。