我的任务是通过单击 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。