Jac*_*cob 1 inheritance integer objective-c ios
我知道我以前做过这个,但我不记得怎么做了.
我有一个整数,我希望能够改变我的另一个类.
我该怎么做?
MainViewClass : UIViewController {
int score;
}
#import "MainViewClass.h"
OtherClass : MainViewClass{
}
Run Code Online (Sandbox Code Playgroud)
然后在OtherClass的.m中我希望能够使用变量得分.
我该怎么做呢?
我在互联网上搜索过,尝试了几件事来试图让它上班不会成功.
谢谢你的期待!祝你有美好的一天.
在MainViewClass.h中,您需要将int添加为该类的属性.
@property (nonatomic, readwrite) int score;
Run Code Online (Sandbox Code Playgroud)
然后在MainViewClass.m中,您将要使用以下内容合成属性:
@synthesize score;
Run Code Online (Sandbox Code Playgroud)
现在,由于您在OtherClass中继承了MainViewClass,您可以使用以下某些组合来访问它的属性.
在你的OtherClass.h中添加
MainViewClass*mainViewClass;
在您的OtherClass.m中,只要您需要访问乐谱,您就应该能够访问它.
mainViewClass = (MainViewClass *) self.parent;
Run Code Online (Sandbox Code Playgroud)
然后使用得分,
mainViewClass.score;
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
3747 次 |
最近记录: |