gpt4 book ai didi

iphone - ios 从不同的类回调 viewController

转载 作者:行者123 更新时间:2023-11-29 03:41:48 25 4
gpt4 key购买 nike

我在从 nsobject 类回调我的 viewController 时遇到问题。这是我的代码:

View Controller :

-(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 类回调我的 View Controller ?

最佳答案

您指的是实例变量 viewController 但正在分配属性 viewController

默认情况下,该属性会自动合成为名为 _viewController 的实例变量。您可以将其更改为显式合成到您的实例变量,但更规范的做法是使用默认的 _viewController 并在您的实现中将其称为 self.viewController文件。

关于iphone - ios 从不同的类回调 viewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18320805/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com