我有问题从nsobject类调用我的viewController。在这里我的代码:ios从不同的类回调viewController
的ViewController:
-(void)startTest:(NSString*)testToRun
{
ViewController *ViewController = [[[ViewController alloc] init] autorelease];
SecondClass *secondClass = [[SecondClass alloc] init];
secondClass.viewController = viewController;
[secondClass doSomething];
}
-(void) createView
{
UIView *newView = [UIView alloc] initWithFrame:[self.view bounds];
self.newView.backgroundColor = [UIColor whiteColor];
[self.view addSubview:newView];
[self.view bringSubviewToFront:newView]
}
NSObject classe:
.h file
#import "ViewController.h"
@class ViewController;
@interface SecondClass : NSObject
{
ViewController *viewController;
}
@property (nonatomic,retain) ViewController *viewController;
-(void) doSomething;
.m file
-(void) doSomething
{
[viewController createView];
}
任何人可能都知道我在做什么错误或我如何从我的NSObject类再打我的视图控制器?
检查以确定viewController实际上仍然存在,并且在您调用它时不为零。 – Jeff
您使用ARC吗? – Jeff
在将视图控制器的指针传递给nsboject类的时刻不是nill,而是在nsobject类中的时候是nil,我不明白为什么 – HelenaM