有没有一种方法可以像在VB.NET中强制转换对象那样在Objective-C中强制转换对象?
例如,我正在尝试执行以下操作:
// create the view controller for the selected item
FieldEditViewController *myEditController;
switch (selectedItemTypeID) {
case 3:
myEditController = [[SelectionListViewController alloc] init];
myEditController.list = listOfItems;
break;
case 4:
// set myEditController to a diff view controller
break;
}
// load the view
[self.navigationController pushViewController:myEditController animated:YES];
[myEditController release];
但是我遇到了编译器错误,因为即使SelectionListViewController继承自FieldEditViewController,SelectionListViewController类中也存在list属性,但FieldEditViewController中不存在。
这是有道理的,但是有一种方法可以将myEditController强制转换为SelectionListViewController,以便我可以访问'list'属性?
例如在VB.NET中,我会这样做:
CType(myEditController, SelectionListViewController).list = listOfItems
谢谢您的帮助!