First of all, I’m new to XCode and programming and my English is not perfect.
I have 2 view controllers, L1ViewController and ImageViewController. In the L1ViewController i have several buttons with an image as background. What I’m trying to do is when you click a button, the action passes a password and an image to the Image View controller. In the ImageViewController I have a UITextfield and a UIImageView. Passing the password string works fine. But passing the image seems harder than I thought. The UIImageView doesn’t display the image.
In my L1ViewController.h I’ve created a
-(IBAction)img1;
In my L1ViewController.m this is the code to pass the image and the passwordstring:
-(IBAction)img1;
{
ImageViewController *img = [[ImageViewController alloc] initWithImage:[UIImage imageNamed:@"myimage.jpg"] AndAnswerString:@"mypassword"];
[self presentModalViewController:img animated:NO];
}
In my ImageViewController I have this code to receive the string and the image:
-(id)initWithImage:(UIImage *)inImage AndAnswerString:(NSString *)inAnswerString
{
if (self = [super init])
{
[inImage release];
[self setImage:inImage];
[self setAnswerString:inAnswerString];
}
return self;
}
-(void)setImage:(UIImage *)inImage
{
[inImage release];
[logoField setImage:inImage];
}
-(void)setAnswerString:(NSString *)inAnswerString
{
answerString = inAnswerString;
}
In my ImageViewController.h I’ve
@interface ImageViewController : UIViewController {
IBOutlet UITextField *answerField;
IBOutlet UIImageView *logoField;
NSString *answerString;
}
@property (nonatomic, retain)NSString *logo;
-(id)initWithImage:(UIImage *)inImage AndAnswerString:(NSString *)inAnswerString;
-(void)setImage:(UIImage *)inImage;
-(void)setAnswerString:(NSString *)inAnswerString;
-(IBAction)enterAnswer;
-(IBAction)back;
Why is my answerstring working fine but shows my ImageViewController no image?
Again, I’m new to XCode, maybe it’s just a stupid fault.
Thanks in Advance!
When your view controller is being initialized, the views have not been loaded yet. (That happens just before your
viewDidLoad:method is called.) Saving the string works because you’re not trying to put it directly intoanswerFieldbut, with the image, you’re trying to updatelogoFieldtoo early.If the text is working, you must have code somewhere that assigns
answerStringtoanswerField.