ios - 通过首先从方法中获取类来设置类

标签 ios objective-c uitableview

我有一个方法可以告诉我该 indexPath 处的对象应该是什么类(基于带字符串的数组);

但是这会引发错误

"Use of undeclared identifier 'instanceCell'

Class companyCellClass = [HomePageFlagIndexing tableCellClassForIndexPath:indexPath];
    companyCellClass *instanceCell = [tableView dequeueReusableCellWithIdentifier:[HomePageFlagIndexing getIdentifierForIndexPath:indexPath]forIndexPath:indexPath];

有没有办法像这样以编程方式设置类?

最佳答案

companyCellClass 是一个 Class 对象而不是一个 Type,用 UITableViewCell 改变它。

如果您随后想要执行在该类 header 中声明的任何操作,首先您必须手动将其向下转换为您的类并执行,或者发送 performSelector。

关于ios - 通过首先从方法中获取类来设置类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35698442/

相关文章:

ios - iTunes Connect 试飞公链有效性

ios - 最后一个 UITableViewCell 中的 UICollectionView 和一致的滚动?如何?

ios - 使用 UITableViewCell 使用 AutoLayout

objective-c - 以编程方式滚动 UIScrollView

ios - 如何从 iPhone 中的文本字段标签获取文本

objective-c - 锁定你自己的 NSPreferencePane?

ios - 版本特定的预处理器宏

ios - UITableViewCell 不遵守取决于内容的约束

ios - NSInvalidArgumentException 原因 : data parameter is nil in UITableView while trying to display the Flickr images

iphone - 删除更多并使用滚动选项显示所有 7 个选项卡