Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/114.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/22.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
Ios 如何将uiviewcontroller强制转换为自定义类_Ios_Objective C_Viewcontroller - Fatal编程技术网

Ios 如何将uiviewcontroller强制转换为自定义类

Ios 如何将uiviewcontroller强制转换为自定义类,ios,objective-c,viewcontroller,Ios,Objective C,Viewcontroller,我有一个自定义列表viewController NSMutableArray *arrOfCtrls = [[NSMutableArray alloc] init]; AViewController *aCtrl = [[AViewController alloc] init]; BViewController *bCtrl = [[BViewController alloc] init]; CViewController *cCtrl = [[CViewController alloc] in

我有一个自定义列表
viewController

NSMutableArray *arrOfCtrls = [[NSMutableArray alloc] init];
AViewController *aCtrl = [[AViewController alloc] init];
BViewController *bCtrl = [[BViewController alloc] init];
CViewController *cCtrl = [[CViewController alloc] init];
DViewController *dCtrl = [[DViewController alloc] init];
[arrOfCtrls addObject: aCtrl];
[arrOfCtrls addObject: bCtrl];
[arrOfCtrls addObject: cCtrl];
[arrOfCtrls addObject: dCtrl];
然后,我想在列表中获取
UIViewController
arrOfCtrls

UIViewController *vCtrl = arrOfCtrls[0];
如何播放vCtrl is
AViewController
? 我想在vCtrl中获取属性,例如我想在AViewController中获取属性

vCtrl.aProperties

谢谢

如果您知道第一个对象是
AViewController
的类型,那么您可以使用此

AViewController *aVC = (AViewController*)arrOfCtrls[0];
如果你不知道,想投这样的支票

AViewController *aVC; 
if ([arrOfCtrls[0] isKindOfClass:[AViewController class]]) { 
    aVC = arrOfCtrls[0];
}

如果您知道第一个对象的类型是
AViewController
,那么您可以使用此

AViewController *aVC = (AViewController*)arrOfCtrls[0];
如果你不知道,想投这样的支票

AViewController *aVC; 
if ([arrOfCtrls[0] isKindOfClass:[AViewController class]]) { 
    aVC = arrOfCtrls[0];
}

AViewController*vCtr=(AViewController*)arrOfCtrls[0]使用
((AViewController*)arrOfCtrls[0])
?我不知道vCtr是AViewController。如何识别vCtr是AViewController
AViewController*vCtr=(AViewController*)arrOfCtrls[0]使用
((AViewController*)arrOfCtrls[0])
?我不知道vCtr是AViewController。如何重新识别vCtr是AVIEWController您根本不需要强制转换,因为
arrOfCtrls[0]
的类型是
id
。我不想要其他类型。我想将UIViewController强制转换为AviewController答案已存在首先检查line@Takashi你明白我说的吗?@Takashi你在问题下方发表评论说你不知道
arrOfCtrls[0]
是AViewController,你想知道如何识别它。然后在回答下面的一条评论中,您声明您不需要
if/else
。你不能两者兼得。如果你不知道它代表什么类型的视图控制器,那么你需要一个
If/else
来确定它的类型,这样你就可以正确地分配值并访问特定的属性。你根本不需要强制转换,因为
arrOfCtrls[0]
的类型是
id
。我不想要If-else。我想将UIViewController强制转换为AviewController答案已存在首先检查line@Takashi你明白我说的吗?@Takashi你在问题下方发表评论说你不知道
arrOfCtrls[0]
是AViewController,你想知道如何识别它。然后在回答下面的一条评论中,您声明您不需要
if/else
。你不能两者兼得。如果您不知道它代表什么类型的视图控制器,那么您需要一个
If/else
来确定它的类型,这样您就可以正确地分配值并访问特定属性。