2012-05-09 13 views
2

どちらの呼び出しが正しいですか?両方の呼び出しに同じ結果があると思われます。iOS:UIImageの初期化

UIImage *img = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"image" ofType:@"png"]]; 

または

UIImage *img = [[UIImage alloc] imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"image" ofType:@"png"]]; 

答えて

4

imageWithContentsOfFileは、クラスの簡易メソッド(クラスメソッド)であるとして、正しいの最初のです。

+2

+1私は2番目のことを間違えました(これは賢明ではありません) – MByD

-3

UIImageを初期化する最も簡単な方法は...

UIImage *img = [UIImage imageNamed: @"image.png"]; 
+3

「UIImage imageNamed」にはメモリの問題があるため、避けるべきです。 – Raptor

+0

これは質問の答えではありませんか? – rishi

+0

@rishiいいえ、コンパイルするだけでは必ずしも機能するとは限りません。 –