- [__ NSArrayM setTableViewStyle:]:创建自定义uitablevewcell时出错

时间:2012-08-08 22:36:51

标签: iphone objective-c ios5

我刚刚在tableview中创建了一个自定义单元格,我在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'

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

2 个答案:

答案 0 :(得分:1)

很难从这段代码中看出你的行为是否符合:

 customCell = (tableCell *)customObjects;

是对的。至少你强迫一个数组看起来很奇怪:

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

tableCell

你的意思是:

 customCell = (tableCell *)obj;

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

答案 1 :(得分: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;
     }
}