Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c PhoneGap AppDelegate主视图控制器_Objective C_Ios_Inheritance_Cordova - Fatal编程技术网

Objective c PhoneGap AppDelegate主视图控制器

Objective c PhoneGap AppDelegate主视图控制器,objective-c,ios,inheritance,cordova,Objective C,Ios,Inheritance,Cordova,我设置了一个PhoneGap应用程序,并仔细研究了一些代码。AppDelegate下有以下对象: @property (nonatomic, strong) IBOutlet CDVViewController* viewController; 然而,再往下就是这条线: self.viewController = [[MainViewController alloc] init]; 这一行实际上是做什么的,因为viewController是一个CDVViewController对象,但现在它

我设置了一个PhoneGap应用程序,并仔细研究了一些代码。AppDelegate下有以下对象:

@property (nonatomic, strong) IBOutlet CDVViewController* viewController;
然而,再往下就是这条线:

self.viewController = [[MainViewController alloc] init];
这一行实际上是做什么的,因为viewController是一个CDVViewController对象,但现在它似乎在说,或者至少将其转换为一个MainViewController对象

此外,MainViewController继承了CDVViewController,因此如果它不以MainViewController开头,又有什么意义呢

 @property (nonatomic, strong) IBOutlet MainViewController* viewController;

它不是以
@property(非原子,强)IBOutlet MainViewController*viewController开始的,因此当self.viewController响应消息的选择器时,self.viewController可以是类CDVViewController或MainViewController,具体取决于运行时响应选择器的是类CDVViewController还是MainViewController


这就是所谓的多态性。您可以查看或。

然后如何使用self.viewController设置MainViewController的属性,当前正在尝试self.viewController.token=@“hello”,结果会出现一个错误,说self.viewController是CDVViewObject,因此不存在这样的属性:如果查看CDVViewObject的属性,我假设没有声明“token”。多态性的威力在于函数的实现,以及它们在运行时的行为。