【问题标题】:Objective C : dequeueReusableCellWithIdentifier:forIndexPath: returns exception [duplicate]目标C:dequeueReusableCellWithIdentifier:forIndexPath:返回异常[重复]
【发布时间】:2015-12-10 12:45:48
【问题描述】:

我在情节提要中制作了原型单元并设置了它的标识符,但是当我调用时

cell=[tableView dequeueReusableCellWithIdentifier:@"ident" forIndexPath:indexPath];

在我的 cellForRowAtIndexPath 方法中我得到了异常:

 unable to dequeue a cell with identifier ident - must register a nib or a class for the identifier or connect a prototype cell in a storyboard

现在,我知道,如果我在情节提要中声明一个原型单元,我不需要显式注册它。 那么...为什么会出现这个异常?

更新: 我发布了两张显示问题的图片:

【问题讨论】:

  • 您是否在情节提要中设置了您的单元格标识符?
  • 是的,我用图片更新答案
  • 标识符为voceUITableViewCell 在哪里?这可能是导致异常
  • 不,它有效(已经尝试过)如果您阅读下面的异常,您阅读cella_opzioni_menu

标签: ios objective-c uitableview storyboard tableviewcell


【解决方案1】:

尝试做这些..

删除这些..

NSString *identificatore=@"voce";

然后做这些..

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
{
    static NSString *yourcellidentifier=@"cella_opzioni_menu";//here write the cell identifier you gave in storyboard..

    cell=[tableView dequeueReusableCellWithIdentifier:yourcellidentifier];

    if(cell == nil)
    {
         ........
    }

    .
    .
    .

}

希望对你有帮助..

【讨论】:

  • 已经试过了:它给了我一个 nil 值......
猜你喜欢
  • 2020-12-16
  • 2021-08-25
  • 1970-01-01
  • 1970-01-01
  • 2013-05-13
  • 2018-03-08
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多