2012-05-09 71 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我誤讀了第二個(這不是一件聰明的事) – MByD

-3

初始化一個UIImage是最簡單的方法...

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

'UIImage imageNamed'有內存問題,因此我們應該避免它。 – Raptor

+0

這不是問題的答案? – rishi

+0

@ rishi不,只是因爲它編譯並不一定意味着它的作品。 –