I play with imageView and there is a method [imageWithContentsOfFile]; But actually it shows nothing after launch. Below the code there is a method [imageNamed:], and it works as usual. Any ideas? Thank,
#import "ViewController2.h"
@interface ViewController2 ()
@property (weak, nonatomic) IBOutlet UIImageView *imageView;
@end
@implementation ViewController2
- (BOOL)prefersStatusBarHidden
{
return YES;
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
UIBarButtonItem *shareItem = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:nil];
UIBarButtonItem *cameraItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCamera target:self action:nil];
NSArray *actionButtonItems = @[shareItem, cameraItem];
self.navigationItem.rightBarButtonItems = actionButtonItems;
NSString *imgPath =[[NSBundle mainBundle] pathForResource:@"google" ofType:@"png"];
self.imageView.image = [UIImage imageWithContentsOfFile:imgPath];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}
@end
I think the problem is that the pathForResource method does not work correctly ...
source
share