Objective-C 新手。从另一个控制器更改控制器中的属性?

发布于 2024-10-14 15:17:16 字数 1459 浏览 2 评论 0原文

背景:我有三种观点。一个介绍性视图、一个上传视图和主视图。作为类(及其各自的标头),我有 rootViewController (SwitchViewController)、IntroViewController 和 UploadViewController。要显示的第一个视图是 IntroView。用户按下一个按钮(在 SwitchViewController 中声明),将他们带到 UploadView,然后在 UploadView 中选择一个图像,然后再次按下该按钮返回到 IntroView。

问题是,当用户使用 UIImagePickerController 选择图像时,切换视图的按钮不会隐藏,我在视图(屏幕)顶部带有徽标的 UIImageView 也不会隐藏。 UIImageView 和 UIButton 都在 SwitchViewController 的标头中声明。

使用的代码:

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

我最近刚刚开始使用 Objective-C 编程,所以如果问题非常重要,请原谅我。我已经看过并正在关注 APRESS 的“Beginning iPhone 3 Development”。但即使它有助于极大地理解基础知识,有时我也会迷失方向。

PS:如果回答问题更清楚,可以在询问时提供 SwitchViewController.h 和 .m 片段代码。但我认为这篇文章本身就很大。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

眼眸印温柔 2024-10-21 15:17:16

@Joze我想我可能已经理解你的问题 switchViewController 是类 UploadViewController 的变量,所以如果你对该变量执行任何操作,它不会影响 switchViewController 视图。因此,当您当时调用 switchViewController 视图时,您必须执行 initWithNibName: bundle: ,然后隐藏按钮和 imageView,还需要执行类似 switchViewController.delegate = self; 的操作。 然后以模态方式或您想要的任何方式调用视图。

附言。我不确定拼写是否正确。我家里没有xcode。
我希望你的问题能够解决。

@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.

感受沵的脚步 2024-10-21 15:17:16

在重构整个代码并更改程序本身的总体结构后,我解决了我的问题。现在我有 3 个视图,每个视图都有一个 viewController 来控制它。所有视图的切换都发生在代表中,因为他可以访问每个人。这样我就可以用每个控制器控制每个属性,没有太大困难。从另一个视图改变一个视图中存在的一个对象的属性是困难的,而且相当不方便,甚至有时是不可能的。

我在提出这个问题时所采取的方法对于必须完成的应用程序来说是短视的。我感谢所有试图提供帮助的人。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文