开发者

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

开发者 https://www.devze.com 2023-02-06 11:22 出处:网络
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), IntroViewCont

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 [...] 开发者_StackOverflow//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.


@Joze i think I may have understood your problem switchViewController is a variable of the class UploadViewController so if you do anything with that variable it wont affect the switchViewController view. so when you are calling the switchViewController view at that time you have to do initWithNibName: bundle: and then hide the button and imageView and also you need to do something like switchViewController.delegate = self; and then call the view modally or what ever way you want it.

PS. i m not sure the that spelling is correct. i dont have xcode at my home. I hope your problem solves with this.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消