ios - 将数据传递给 ViewController 问题

标签 ios objective-c iphone xcode

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

相关文章:

ios - 旋转图像变得扭曲和模糊?

iphone - 单击 UIAlertView 时崩溃

javascript - 我可以在 UIWebViewDelegate 中处理警报吗?

ios - Xcode 连接到 MS SQL 数据库

iphone - 应用程序在 iPhone 上崩溃但在模拟器或 iPad 上不崩溃?

ios - 为viewController实例创建属性时,找不到viewController

ios - 应用程序进入后台时如何播放通知声音?

ios - 从 iOS 中的音频中提取高音和低音

ios - Plupload with iOS 仅适用于新照片,不适用于相机胶卷

ios - 如果另一列存在,SQLite 更新列