0

我刚刚在表格视图中创建了一个自定义单元格,我在 UITableViewDelegate 方法中调用了自定义单元格

--(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

这就是我的代码的样子:

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

        static NSString *cellId = @"cellIdetifier";
        static NSString *cellId2 = @"cellId2";

        tableCell *customCell = [tableView dequeueReusableCellWithIdentifier:cellId2];
        if(customCell == nil){

            NSArray *customObjects = [[NSBundle mainBundle]loadNibNamed:@"tableCell" owner:self options:nil];
            for(id obj in customObjects){

                if([obj isKindOfClass:[tableCell class]]){

                    customCell = (tableCell *)customObjects;
                    break;
                }

            }


        }

        return customCell;

}

我收到一个错误,上面写着

 creatingcustomcell[693:f803] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayM setTableViewStyle:]: unrecognized selector sent to instance 0x6d6c7f0'

请帮助我,我不知道刚刚发生了什么。

4

2 回答 2

1

很难从这段代码中看出你的强制是否符合要求:

 customCell = (tableCell *)customObjects;

是正确的。至少强制数组看起来很奇怪:

NSArray *customObjects = [[NSBundle mainBundle]loadNibNamed:@"tableCell" owner:self options:nil];

给你的tableCell

你的意思是:

 customCell = (tableCell *)obj;

此外,您可能希望遵循类名应大写的建议

于 2012-08-08T22:50:14.997 回答
0
 if([obj isKindOfClass:[tableCell class]]){
      customCell = (tableCell *)customObjects;
      break;
 }

您正在将单元格设置为整个数组

改为这样做

 for (int i=0; i < customObjects.count; i++) {

     if([customObjects objectAtIndex:i] isKindOfClass:[tableCell class]]){

          customCell = (tableCell *)[customObjects objectAtIndex:i];
          break;
     }
}
于 2012-08-08T23:45:45.733 回答