开发者

iPhone Development: How to transfer information from one .m file to another

开发者 https://www.devze.com 2023-03-28 13:01 出处:网络
I am new to iPhone development, I have a program that has 7 UITextFields visableenter code here. When the user picks a number on the UIPicker View (1-5) that many UITextFields become hidden and unusab

I am new to iPhone development, I have a program that has 7 UITextFields visableenter code here. When the user picks a number on the UIPicker View (1-5) that many UITextFields become hidden and unusable. That program works well. I want to have the same number that was picked from that .m file and transfered to开发者_StackOverflow中文版 another .m file so that 1-5 UITextFields are hidden and unusable. If it matters, the first .m file is abc.m and the second one is bca.m if it matters I use [textfield sethidden= YES]

Thanks


You need to keep references to all those objects in the class, and define properties to them so that you can refer to them in the second .m file.

So assuming you have a classes, abc.m

@interface abc {

UITextField *text1;

}

@property (nonatomic, retain) UITextField *text1;

@end

@implementation abc

@synthesize text1;

- (id) init {

if (self = [super init]) {
text1 = [[UITextField alloc] initWithFrame:CGRectMake(0,0,150,10)];
}
return self;
}

- (void)dealloc {

[text1 release];
[super dealloc];
}

Then you can use the text1 property to refer to that text field, given that you have instantiated the object in the second class, or hold a reference to it.


[[MyClass alloc] initWithFrame: CGRectZero andSomeString: @"Hello World!"];

MyClass

- (id)initWithFrame:(CGRect)frame andSomeString:(NSString*)aString
{
    if (self = [super initWithFrame:frame]) 
    {
        someString = aString;
    }
    return self;
}


You could try making a BOOL or several BOOL variables and set it equal to YES or NO then put that into your text fields.

    BOOL isVisible = YES;
    [textfield setHidden:isVisible];

and then if you use a pushViewController you can set the isVisible from bca.m equal to the isVisible in abc.m

    viewController.isVisible = isVisible; 
0

精彩评论

暂无评论...
验证码 换一张
取 消