从另一个UIView访问UIView的成员变量 [英] Accesing a UIView's member variable from another UIView

查看:39
本文介绍了从另一个UIView访问UIView的成员变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在iPhone上有三种不同的看法.我可以在不同的视图之间成功切换,但是我想在第二个视图的ViewDidLoad方法中访问第一个视图的变量,但是我无法获取它,所以请帮我解决这个问题.

I have Three different views on iphone. I switch between different views successfully, but I want to access the 1st view's variable in second view's ViewDidLoad method but I can't get it so plz help me on that.

推荐答案

具有如下声明的UIView的两个子类:

Having two subclasses of UIView declared like so:

@interface ViewOne : UIView {
    NSString *someVar;
}

@property (nonatomic, copy) NSString *someVar;

@end

@interface ViewTwo : UIView {
    NSString *referenceToSomeVar;
}

@property (nonatomic, retain) NSString *referenceToSomeVar;

@end

您可以在第一个视图中对"someVar"变量进行以下引用

You could do the following the reference the "someVar" variable from the first view

ViewOne *view1 = [[ViewOne alloc] init];
view1.someVar = @"This is the original variable";

ViewOne *view2 = [[ViewOne alloc] init];
view2.referenceToSomeVar = view1.someVar;

这篇关于从另一个UIView访问UIView的成员变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆