2012-05-09 73 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不,只是因为它编译并不一定意味着它的作品。 –