Sunday, November 16, 2008

Finally Displayed an Image

I'm not liking the Cookbook very much. It seems to try to be a combination of advanced-user-cookbook and beginner-tutorial and does neither very well. The author seems to take a huge number of short cuts, seeming to assume you went through the whole beta SDK process along with her. I didn't. I'm new to the game.

Anyway, since it wasn't really helping me, I decided to just try and draw a single picture on the simulator. What a pain, but then I had a similar problem with C#. UIImage:drawAtPoint doesn't actually draw at a point, for example, until you add it to a UIImageView. I was trying to draw the image raw, but that wouldn't happen. I suspect it's doable, but there's too much linkage with the .xib file that gets created in a basic project. Anyway, after much wailing and gnashing of teeth, I finally got it. Here it is, without the proper memory handling (because handling that's still new to me as well):

UIImage *myImage = [UIImage imageNamed:(@"Olga-Kurylenko-1.jpg")];
UIImageView *myImageView = [[UIImageView alloc] initWithImage:myImage];
[myImage drawAtPoint:(CGPointMake(50.0,50.0))];
[self.view addSubview:myImageView];

So there you are. I need to free up the "myImageView" variable and come to grips on who the heck frees the "myImage" variable. Oh, this goes into the "viewDidLoad:" method, by the way. The logic is that viewDidLoad: gets called and when the super viewDidLoad gets called, then the image view will also get displayed.

No comments: