我有問題從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