我试图隐藏一个物体 在我眼中的主计长, 代码执行 从定制类, 但该物体是零。
< pronger > FirstView 主计长.h
#import <UIKit/UIKit.h>
@interface FirstViewController : UIViewController {
IBOutlet UILabel *testLabel;
}
@property (nonatomic, retain) IBOutlet UILabel *testLabel;
- (void) hideLabel;
FirstViewController.m I synthesize testLabel and I have a function to hide it. If I call the function from viewDidAppear it works, but I want to call it from my other class. When called from the other class, testLabel is nil
#import "FirstViewController.h"
#import "OtherClass.h"
@implementation FirstViewController
@synthesize testLabel;
- (void) hideLabel {
self.testLabel.hidden=YES;
NSLog(@"nil %d",(testLabel==nil)); //here I get nil 1 when called from OtherClass
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
OtherClass *otherClass = [[OtherClass alloc] init];
[otherClass hideThem];
//[self hideLabel]; //this works, it gets hidden
}
< 坚固 > 其他千字节.h 坚固 >
@class FirstViewController;
#import <Foundation/Foundation.h>
@interface OtherClass : NSObject {
FirstViewController *firstViewController;
}
@property (nonatomic, retain) FirstViewController *firstViewController;
-(void)hideThem;
@end
OtherClass.m calls the hideLabel function in FirstViewController. In my original project, (this is an example obviously, but the original project is at work) I download some data here and I want to hide my loading label and indicator when download is done
#import "OtherClass.h"
#import "FirstViewController.h"
@implementation OtherClass
@synthesize firstViewController;
-(void)hideThem {
firstViewController = [[FirstViewController alloc] init];
//[firstViewController.testLabel setHidden:YES]; //it doesn t work either
[firstViewController hideLabel];
}
有什么想法吗?