iphoneobjective-ccocoa-touchiboutlet

Objective-C Novice. Change property in Controller from another Controller?


The context: I have three views. One Introductory view, an Upload view and the Main view. As classes (With their respective headers) I have the rootViewController (SwitchViewController), IntroViewController and UploadViewController. The first view to be shown is IntroView. The user presses a button (declared in SwitchViewController) that takes them to the UploadView, then in the UploadView they get to choose an image and press the button again to go back to IntroView.

The thing is that while the user gets to pick the image with UIImagePickerController the button to switch views won't hide nor a UIImageView I have with a logo on top of the view(screen). The UIImageView and the UIButton are both declared in SwitchViewController's header.

The code used:

UploadViewController.h

#import [...] //Imports
@class SwitchViewController;
@interface UploadViewController : 
UIViewController <UIImagePickerControllerDelegate, 
UINavigationControllerDelegate,UIActionSheetDelegate> {
    UITextField *imageTextField;
    UIImageView *uploadedImage;
    SwitchViewController *switchViewController;
[...]
}

@property (nonatomic, retain) SwitchViewController *switchViewController;
@property (nonatomic, retain) IBOutlet UITextField *imageTextField;
@property (nonatomic, retain) IBOutlet UIImageView *uploadedImage;
[...]
@end

UploadViewController.m

[...]
- (IBAction) selectImageButtonPressed {
self.switchViewController.submitButton.hidden = YES;
self.switchViewController.imageLogo.hidden = YES;

[...] //continues

I just begun recently programming in objective-c so please forgive me if the question is very essential. I have looked and am following "Beginning iPhone 3 Development" of APRESS. But even if it helps to greatly understand the basics sometimes I get lost.

PS: If it is clearer to answer the question the SwitchViewController.h and .m snippet codes can be provided if asked. But I thought this text is big as it is.


Solution

  • I solved my problem after refactoring the whole code and changing the general structure of the program itself. Now I have 3 views and each with a viewController to control it. All the switching of views occurs in the Delegate since he has access to everyone. That way I can control every property with every controller, without much difficulty. Changing the property of one of the objects present in one view from another view is difficult and rather inconvenient if not sometimes impossible.

    The approach I took when asking this question was short sighted for the application that had to be done. I thank all those who tried to help.