2
votes

I'm quite new to iOS development. I'm trying to create an iPad app where I need to display an image (here I used a.png). Image shows properly on the first view controller. Then, I navigate to other view using

[self.navigationController pushViewController:<#(UIViewController *)#> animated:<#(BOOL)#>]

On the second viewcontroller, where I navigate to, I have put an UIImageView on the viewcontroller in the .xib using the interface builder. But, on running, when I navigate to the second viewcontroller, the imageview in the second viewcontroller is not displayed.

That is, on any normal viewcontroller uiimageview is working perfectly, but after navigation (i.e. self.navigationController pushViewController), the uiimageview isn't displayed in the next viewcontroller.

I tried debugging. After running the flow goes to the viewDidLoad of the second viewcontroller. I even tried to alloc the UIImageView in the viewDidLoad, on running the control goes to alloc of UIImageView, and even is allocated properly (that is not nil). But still, I'm not sure why image is not visible.Earlier I figured maybe it is not loading and on appear it is nil, but on debugging I found it is not nil.

I'm stumped. Can't figure out what I may be missing.

Suggestions please. I need help to figure out what all may be the cause of UIImageView image not being displayed.

1
check IBOutlet connection?Balu
Paste your code what you had tried ?Manu
code PhotoGalleryViewController *photoGalleryViewController = [[PhotoGalleryViewController alloc] initWithNibName:@"PhotoGalleryViewController" bundle:nil]; [self.navigationController pushViewController:photoGalleryViewController animated:YES];Monty
remove imageview allocation in photoGalleryViewController viewDidLoad method.Balu
in the photoGalleryViewController, I have assigned the image to uiimageview in the xibMonty

1 Answers

0
votes

check your UIImageView is Properly Connected to file's Owner or Not ??

  • create object of UIImageView in .h file

  • And Set @property and @synthesize of UIImageView

  • And Then After Check Your Image (Which put on UIImageView) Has Valid Name.

EDITE:

Try To Add UIImageView Programmatically

- (void)viewDidLoad
{
    [super viewDidLoad];
    UIImageView *myImageView = [[UIImageView alloc] initWithFrame: CGRectMake(10, 10, 320, 375)] ; // set Frame as you need
    [myImageView setImage: [UIImage imageNamed:@"MYImage.png"]];
    [self.view addSubview: myImageView];
}