【发布时间】:2011-06-24 18:36:47
【问题描述】:
基本上,我想在主类持有指针的子类中调用主类的函数。
我知道我可以让主类启动子类并将函数附加到它。但我不希望这样,我希望子类使用它的 init 函数来初始化自己。
有什么方法可以从 someClass 调用 doSomething 吗?
一些显示我想要的基本代码:
在 MainViewController.h 中:
@class SomeClass;
@interface MainViewController : UIViewController {
SomeObject *someInformation;
SomeClass *someInstance;
}
@property (nonatomic, strong) SomeClass *someInstance;
-(void)doSomething:(id)sender;
@end
在 MainViewController.m 中:
@implementation MainViewController
@synthesize someInstance;
-(void)doSomething:(id)sender {
//do something to someInformation
}
@end
在 SomeClass.h 中:
@interface SomeClass : NSObject {
UIStuff *outstuff;
}
@property (strong, nonatomic) UIStuff *outstuff;
-(void)somethingHappened:(id)sender;
@end
在 SomeClass.m 中
@implementation SomeClass
@synthesize outStuff;
-(IBAction)somethingHappened:(id)sender {
//call doSomething to the main class that points to this class
}
@end
【问题讨论】:
-
你能解释清楚吗?你想从哪个类调用什么函数?
-
我想从 SomeClass 中调用 doSomething。 (将其添加到问题中)
标签: objective-c xcode