Hi there. I'm finally finding the time to try my hand at some baby steps* in iPhone programming. I am currently working on a very simple dungeon crawler as this is something I've made a few times before on other platforms and in other languages.
I have a ViewController named "DungeonViewController" and I have a class named "Room". The idea is to have an instance of the Room.class displaying an image (or rather two) to an UIImageView in the DungeonView.xib.
I have made an object of the type Room in the xib-file and connected the outlet "floor" to the UIImageView in question. It is (obviously) not working however. Here are some code snippets:
Room.h
Code:
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
@interface Room : NSObject {
IBOutlet UIImageView *floor;
}
@property (nonatomic, retain) UIImageView *floor;
-(void) displayRoomFloor:(id)sender;
@end
Room.m
Code:
#import "Room.h"
@implementation Room
@synthesize floor;
-(void)displayRoomFloor:(id)sender
{
NSLog(@"displayRoomFloor");
floor.animationImages = [NSArray arrayWithObjects: [UIImage imageNamed:@"floor1.png"],[UIImage imageNamed:@"floor2.png"], nil];
floor.animationDuration = 0.2;
floor.animationRepeatCount = 0;
[floor startAnimating];
}@end
Now, the animation bit should work just fine as it does when it is included directly in my DungeonViewController/viewDidLoad. At the moment I'm trying to achieve the same thing by calling an instance of room like below:
Code:
-(void)viewDidLoad {
[super viewDidLoad];
room = [[[Room alloc] init] autorelease];
[room displayRoomFloor:self];
}
I know from the console that the call to the instance method is achieved but it is not displaying anything (or at least not doing so in a visible manner).
I believe I might have some misconception about the right way to hook this kind of stuff up? My idea is to use the Room-class to display graphical details for each room in a dungeon and as such it made sense to me that each room should actually be an object...
Anyone?
Anyone, actually understand what I'm writing right now? Not sure
I do. Time to open up another bottle of beer. It's the best thing that doesn't help.
*I'm not quite sure how I manage to makes steps of any sort with my hands. Ah, the blessing of mixed metaphors...