2016-02-29 43 views
0

我有一个方法告诉我该索引路径上的对象应该是什么类(基于包含字符串的数组)。通过先从方法获取类来设置类

然而,这引发错误

“未声明的标识符的使用 'instanceCell'

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

有没有一种方法以编程方式这样设置类?

+0

你寄存器单元或笔尖与标识? –

+0

是的 - 它有 - 我只需要检查类,设置它,然后调用我的方法[instanceCell setUpWithType:0]; –

回答

2

companyCellClass是一个Class对象而不是T ype,更改为UITableViewCell

如果您希望执行在该类头中声明的任何操作,首先必须手动向类下拉它并执行操作,或者发送performSelector。

+0

如果我这样做,它不会让我调用单元格上的方法,这对于这个类是独一无二的。 instanceCell.delegate = self;例如 –

+0

然后只为它们或一个协议创建一个抽象/父类,并将TableViewCell转换为该类型并分配委托。 – ogres

+0

或者只是用id(不带*标记)更改UITableViewCell,然后调用[instanceCell setDelegate:self] – ogres

0

对于

[tableView dequeueReusableCellWithIdentifier:[HomePageFlagIndexing getIdentifierForIndexPath:indexPath]forIndexPath:indexPath]; 

每个可能的标识符你要拨打:

- (void)registerNib:(UINib *)nib forCellReuseIdentifier:(NSString *)identifier 
// or 
- (void)registerClass:(Class)cellClass forCellReuseIdentifier:(NSString *)identifier 

看到苹果的doc https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITableView_Class/#//apple_ref/occ/instm/UITableView/registerNib:forCellReuseIdentifier