【发布时间】:2010-10-16 00:00:23
【问题描述】:
有没有一种方法可以像在 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];
但是我得到一个编译器错误,因为“list”属性存在于 SelectionListViewController 类中,但不在 FieldEditViewController 上,即使 SelectionListViewController 继承自 FieldEditViewController。
这是有道理的,但是有没有办法将 myEditController 转换为 SelectionListViewController 以便我可以访问“列表”属性?
例如在 VB.NET 中我会这样做:
CType(myEditController, SelectionListViewController).list = listOfItems
感谢您的帮助!
【问题讨论】:
标签: objective-c