Hi,
I just started programming with Xcode 4 working with a book called "Entwickeln mit dem iPhone SDK" (on german, published in english, don't know the original name).
But I have a little problem with a code provided bye the book, that was written for Xcode 3. Hopefully you can help me with that
Here's the situation: I have a view based app an a class called "Movie" (created the Movie.h and Movie.m files). In the default MovieViewController I can use this class perfectly. Now I added a MovieEditor UIViewController subclass.
Despite the fact, that I added @class Movie in the .h file and created a variable like I did with the MovieViewController (with all the @property and @synthesize stuff) I can not access for example self.movie.title what is easily possible in the files created with creating the project. I have no declaration like "Movie *movie = [[Movie alloc] init] in the following code, but that is not working too
Movie.h
Movie.m
MovieEditorViewController.h (file I created)
Important part of the MovieEditorViewController.m file
Best regards
KingJames
PS: writing this from Germany, reply could take it's time
I just started programming with Xcode 4 working with a book called "Entwickeln mit dem iPhone SDK" (on german, published in english, don't know the original name).
But I have a little problem with a code provided bye the book, that was written for Xcode 3. Hopefully you can help me with that
Here's the situation: I have a view based app an a class called "Movie" (created the Movie.h and Movie.m files). In the default MovieViewController I can use this class perfectly. Now I added a MovieEditor UIViewController subclass.
Despite the fact, that I added @class Movie in the .h file and created a variable like I did with the MovieViewController (with all the @property and @synthesize stuff) I can not access for example self.movie.title what is easily possible in the files created with creating the project. I have no declaration like "Movie *movie = [[Movie alloc] init] in the following code, but that is not working too
Movie.h
Code:
@interface Movie : NSObject
{
NSString *title;
NSNumber *boxOfficeGross;
NSString *summary;
}
-(id)initWithTitle:(NSString *)NewTitle boxOfficeGross:(NSNumber *)newBoxOfficeGross summary:(NSString *)newsummary;
@property (nonatomic, copy) NSString *title;
@property (nonatomic, copy) NSNumber *boxOfficeGross;
@property (nonatomic, copy) NSString *summary;
@end
Movie.m
Code:
#import "Movie.h"
@implementation Movie
@synthesize title, summary, boxOfficeGross;
-(id)initWithTitle:(NSString *)NewTitle boxOfficeGross:(NSNumber *)newBoxOfficeGross summary:(NSString *)newsummary
{
self = [super init];
if (self != Nil) {
self.title = NewTitle;
self.boxOfficeGross = newBoxOfficeGross;
self.summary = newsummary;
}
return self;
}
-(void)dealloc
{
self.title = Nil;
self.boxOfficeGross = nil;
self.summary = nil;
[super dealloc];
}
- (id)init
{
self = [super init];
if (self) {
// Initialization code here.
}
return self;
}
@end
MovieEditorViewController.h (file I created)
Code:
#import <UIKit/UIKit.h>
@class Movie;
@interface MovieEditorViewController : UIViewController <UITextFieldDelegate>
{
UITextField *titleField;
UITextField *boxOfficeGrossField;
UITextField *sumamryField;
Movie *movie;
}
@property (nonatomic, retain) IBOutlet UITextField *titleField;
@property (nonatomic, retain) IBOutlet UITextField *boxOfficeGrossField;
@property (nonatomic, retain) IBOutlet UITextField *summaryField;
@property (nonatomic, retain) Movie *movie;
@end
Important part of the MovieEditorViewController.m file
Code:
#import "MovieEditorViewController.h"
@implementation MovieEditorViewController
@synthesize titleField, boxOfficeGrossField, summaryField, movie;
-(void)viewWillAppear:(BOOL)animated //here start the problems
{
self.titleField.text = self.movie.title; //property title cannot be found in forward class movie
NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
[formatter setNumberStyle:NSNumberFormatterCurrencyStyle];
self.boxOfficeGrossField.text = [formatter stringFromNumber:self.movie.boxOfficeGross];
[formatter release];
self.summaryField.text = self.movie.summary;
}
Best regards
KingJames
PS: writing this from Germany, reply could take it's time