iPhone 开发:如何将信息从一个 .m 文件传输到另一个

发布于 2024-11-29 14:38:38 字数 282 浏览 3 评论 0原文

我是 iPhone 开发新手,我有一个程序,有 7 个 UITextFields 可见在此处输入代码。当用户在 UIPicker 视图(1-5)上选择一个数字时,许多 UITextField 会变得隐藏且无法使用。该程序运行良好。我想要从该 .m 文件中选取相同的数字并将其传输到另一个 .m 文件,以便 1-5 UITextFields 被隐藏且无法使用。如果重要的话,第一个 .m 文件是 abc.m,第二个是 bca.m 如果重要的话我使用 [textfield sethidden= YES]

谢谢

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 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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

云雾 2024-12-06 14:38:38

您需要保留对类中所有这些对象的引用,并为它们定义属性,以便您可以在第二个 .m 文件中引用它们。

因此,假设您有一个类 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];
}

那么您可以使用 text1 属性来引用该文本字段,前提是您已经在第二个类中实例化了该对象,或者保存了对它的引用。

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.

筑梦 2024-12-06 14:38:38
[[MyClass alloc] initWithFrame: CGRectZero andSomeString: @"Hello World!"];

我的班级

- (id)initWithFrame:(CGRect)frame andSomeString:(NSString*)aString
{
    if (self = [super initWithFrame:frame]) 
    {
        someString = aString;
    }
    return self;
}
[[MyClass alloc] initWithFrame: CGRectZero andSomeString: @"Hello World!"];

MyClass

- (id)initWithFrame:(CGRect)frame andSomeString:(NSString*)aString
{
    if (self = [super initWithFrame:frame]) 
    {
        someString = aString;
    }
    return self;
}
木緿 2024-12-06 14:38:38

您可以尝试创建一个 BOOL 或多个 BOOL 变量,并将其设置为 YES 或 NO,然后将其放入文本字​​段中。

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

然后如果您使用pushViewController,您可以将bca.m中的isVisible设置为等于abc.m中的isVisible

    viewController.isVisible = isVisible; 

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; 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文