我的任务是通过单击 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。
最佳答案
首先,阅读Resource Management in View Controllers
我认为,问题是首先您通过属性设置 UIImageView,然后在模式 Controller 中加载 View 时从 xib 设置它。
关于ios - 将数据传递给 ViewController 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13347462/