我正在尝试创建一个购物车对象,该对象应该能够注册registerClass:forCellWithReuseIdentifier:
in之类的其他产品类UICollectionView
并动态地转换对象。
例如:
@property (nonatomic) Class productClass;
_productClass *product = (_productClass*)array[0];
在objective-c中允许这样做吗?如果是,请提供一些示例代码,谢谢!
如果要动态创建事先不知道的类的实例,这很容易:
Class type = …;
id instance = [[type alloc] init];
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句