Need help displaying an image in UIViewController

Discussion in 'iOS Programming' started by yoavhorev, Jul 11, 2009.

  1. yoavhorev macrumors newbie

    Joined:
    Jul 11, 2009
    #1
    Hi,
    I tried to add a UIImageView to my UIViewController but it doest seems to work. I dont know if what I am doing is the best way to go but what I am trying to achieve is to have a bit f text, a few buttons and an image all displayed on the same screen.
    in the .h file I wrote:

    #import <UIKit/UIKit.h>

    @class HelloUniverseController;

    @interface HelloUniverseAppDelegate : NSObject <UIApplicationDelegate> {
    UIWindow *window;
    HelloUniverseController *hvController;
    UIImageView *image;
    }

    @property (nonatomic, retain) IBOutlet UIWindow *window;
    @property (nonatomic, retain) HelloUniverseController *hvController;
    @property (nonatomic, retain) UIImageView *image;

    @end

    in the .m I wrote:

    #import "HelloUniverseAppDelegate.h"

    @implementation HelloUniverseAppDelegate

    @synthesize window, hvController, image;


    - (void)applicationDidFinishLaunching:(UIApplication *)application {

    HelloUniverseController *hvc = [HelloUniverseController alloc];
    hvc = [hvc initWithNibName:mad:"HelloUniverse" bundle:[NSBundle mainBundle]];

    self.hvController = hvc;


    [hvc release];

    [window addSubview:[self.hvController view]];


    UIImageView *img = [[UIImageView alloc] imageNamed:mad:"Picture.png"];


    self.image = img;

    [img release];

    [self.hvController addSubview:[(self.image) view]];



    // Override point for customization after application launch
    [window makeKeyAndVisible];
    }


    - (void)dealloc {
    [hvController release];
    [window release];
    [super dealloc];
    }


    @end

    the UIViewController works just fine, I just cant get the picture to work.
    Thanks
    Yoav.
     
  2. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
    This line:

    UIImageView *img = [[UIImageView alloc] imageNamed:mad:"Picture.png"];

    Appears to be totally wrong. You need an init or initWithXXX method (probably initWithImage:). Don't try and make up methods: read the documentation!
     

Share This Page