Objective-C 新手。从另一个控制器更改控制器中的属性?
背景:我有三种观点。一个介绍性视图、一个上传视图和主视图。作为类(及其各自的标头),我有 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
@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 classUploadViewController
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 doinitWithNibName: bundle:
and then hide the button and imageView and also you need to do something likeswitchViewController.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.
在重构整个代码并更改程序本身的总体结构后,我解决了我的问题。现在我有 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.