从另一个View Controller类分配图像

时间:2015-05-06 13:50:35

标签: ios objective-c

我在一个View Controller类中有一个未分配的UIImageView。我想使用UIImage ImageNamed分配它:@“examplePic.png”来自另一个View Controller类的.m文件

这是我的代码 -

protected DesiredCapabilities getDesiredCapabilities() {
    DesiredCapabilities cap = new DesiredCapabilities();
    cap.setCapability(CapabilityType.BROWSER_NAME, "");
    cap.setCapability("platformName", "ANDROID");
    cap.setCapability("deviceName", "08e1cfd3"); // Tablet ID
    cap.setCapability("platformVersion", "4.4");
    cap.setCapability("app", apkPath);
    cap.setCapability("appPackage", APP_PACKAGE);
    cap.setCapability("noSign", true);
    cap.setCapability("fullReset", false);
    cap.setCapability("intent-action", "android.intent.action.MAIN");

    return cap;
 }

2 个答案:

答案 0 :(得分:0)

在尝试设置UIImageView属性之前,看起来image未初始化。请尝试以下方法:

class1.myImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"examplePic.png"]]

答案 1 :(得分:0)

问题是您的descriptor尚未初始化。解决这个问题:

为UIImage添加新属性:

import types

class Timed(object):
    def __init__(self, f):
        self.func = f

    def __call__(self, *args, **kwargs):
        start = dt.datetime.now()
        ret = self.func(*args, **kwargs)
        time = dt.datetime.now() - start
        ret["time"] = time
        return ret

   def __get__(self, instance, cls):           
       return types.MethodType(self, instance, cls)

初始化将被推入堆栈的UIImageView时,请尝试以下操作:

@property (nonatomic) UIImage *imageForImageView;

然后,在UIViewController UIViewController *someViewController = [[UIViewController alloc] initWithNibName:@"SomeNibName" bundle:nil]; someViewController.imageForImageView = image; [self.navigationController pushViewController:someViewController animated:YES]; viewDidLoad中,您可以将someViewController作为图像分配给imageForImageView

这样,您可以确保UIImageView在为其分配UIImageView时实际存在内存。