【发布时间】:2012-11-01 02:21:04
【问题描述】:
我的任务是通过单击 FirstViewController 上的按钮在 SecondViewController 的 UIImageView 中设置背景图像。
FirstViewController.h:
#import <UIKit/UIKit.h>
#import "SecondViewController.h"
@class SecondViewController;
@interface ViewController : UIViewController
{
SecondViewController *secondViewData;
}
// pointer to second view
@property (nonatomic, strong) SecondViewController *secondViewData;
// buttons
- (IBAction)changeBack:(id)sender;
@end
FirstViewController.m 中的按钮方法:
- (IBAction)changeBack:(id)sender {
SecondViewController *svc = [[SecondViewController alloc] init];
self.secondViewData = svc;
svc.back = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"1.png"]];
svc.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentViewController:svc animated:YES completion:nil];
}
SecondViewController.h:
#import <UIKit/UIKit.h>
#import "FirstViewController.h"
@interface SecondViewController : UIViewController
@property (strong, nonatomic) IBOutlet UIImageView *back;
@end
返回 - 它是 SecondViewController 中的 IBOutlet UIImageView。 我还在 SecondViewController.m 中导入了 FirstViewController.h。 我试图将字符串传递给 SecondViewController - 它在 SecondViewController 的 -ViewDidLoad 中记录良好,但无法设置 UIImageView。
【问题讨论】:
-
“back-它是 SecondViewController 中的 UIImageView”是什么意思?又回来了一个 IBOutlet。如果没有,那么在 SecondViewController 中查看与“返回”有关的任何代码会很有帮助。
-
在视图之间传输数据的好方法 - iphonedevsdk.com/forum/iphone-sdk-development/…
-
这是一个 ARC 项目吗?在 SecondViewController 的 xib 中重新设置了吗?即使您务实地进行设置,当视图在 svc 中加载时,它也会被任何默认值覆盖。最好的方法可能是将图像作为值传递到自定义 init 方法中,然后在 svc viewDidLoad 方法中加载。
-
我建议不要为
back设置图像视图,而是为图像(不是图像视图)设置一个属性,并让SecondViewController的viewDidLoad设置图像视图以使用图像您在此处设置的属性。一般来说,你不应该在viewDidLoad之前搞乱控件,因为视图控制器的视图可能还没有创建。 -
rdelmar,是的,它是一个 IBOutlet
标签: ios objective-c iphone xcode