I would have a text that I wanna display in a detailviewcontroller. I followed a tutorial but this is a UIImage and I want it to change it in a UILabel.
StedenNamen.m
Code:
#import "StedenNamen.h"
@implementation StedenNamen
@synthesize books;
@synthesize bookImages;
- (id) init {
self = [super init];
NSMutableArray *tmpBooks = [[NSArray alloc] initWithObjects:
@"Aalst",
@"Aardenburg",
@"Aarle-Rixtel",
@"Achterveld",
@"Achtmaal",
@"Aerdt",
@"Zwolle",
nil];
self.books = tmpBooks;
[tmpBooks release];
NSMutableArray *tmpImages = [[NSArray alloc] initWithObjects:
@"Plaatsnaam",
@"Plaats 2",
@"Plaats 3",
nil];
self.bookImages = tmpImages;
[tmpImages release];
return self;
}
- (int)getNumberOfBooks {
return [books count];
}
- (NSString *)getBookTitleAtIndex:(int)index {
return [books objectAtIndex:index];
}
- (UIImage *)getBookImageAtIndex:(int)index {
UIImage *bookImage = [UIImage imageNamed:[bookImages objectAtIndex:index]];
return bookImage;
}
- (void) dealloc {
[books release];
[bookImages release];
[super dealloc];
}
@end
DetailViewController.h
Code:
#import <UIKit/UIKit.h>
@class StedenNamen;
@interface StedenDetailViewController : UIViewController {
UIImageView *bookImageView;
StedenNamen *booksModel;
int bookIndex;
}
@property (nonatomic, retain) IBOutlet UIImageView *bookImageView;
@property (nonatomic, retain) StedenNamen *booksModel;
- (void)setIndexForBookImage:(int)index;
@end
DetailViewController.m
Code:
#import "StedenDetailViewController.h"
#import "StedenNamen.h"
@implementation StedenDetailViewController
@synthesize bookImageView;
@synthesize booksModel;
- (void)setIndexForBookImage:(int)index {
bookIndex = index;
}
- (void)viewWillAppear:(BOOL)animated {
bookImageView.image = [booksModel getBookImageAtIndex:bookIndex];
[super viewWillAppear:animated];
}
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc. that aren't in use.
}
- (void)viewDidUnload {
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc {
[bookImageView release];
[booksModel release];
[super dealloc];
}
@end
Is this possible?