10

このエラーが発生する理由を誰か教えてもらえますか?

ここに私の.mファイルがあります:

#import "ListaParticipantesViewController.h"
#import "Participantes.h"
#import "ModParticipantesViewController.h"

@implementation ListaParticipantesViewController

@synthesize dao;
@synthesize participantes;

- (void)viewDidLoad
{
    dao = [[ParticipantesDAO alloc] init];
    participantes = [[NSMutableArray alloc] init];
    participantes = [dao getDatos];
    [super viewDidLoad];

}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [participantes count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"celda";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    cell.textLabel.text = [[participantes objectAtIndex:[indexPath row]] valueForKey:@"nombre"];

    return cell;
}

#pragma mark - Table view delegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{

    ModParticipantesViewController *destino = [self.storyboard instantiateViewControllerWithIdentifier:@"visualizacion"];
    Participantes *tmp = [participantes objectAtIndex:[indexPath row]];
    destino.participante = tmp;

    [self.navigationController pushViewController:destino animated:YES];
}

@end

表示されるエラーは次のとおりです。

2013-04-13 17:40:20.235 Registro[5314:c07] *** Assertion failure in -[UITableView _configureCellForDisplay:forIndexPath:], /SourceCache/UIKit_Sim/UIKit-2380.17/UITableView.m:5471
2013-04-13 17:40:20.237 Registro[5314:c07] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath:'
*** First throw call stack:
(0x209d012 0x11aae7e 0x209ce78 0xc40665 0x1a4c1b 0x13940c 0x1a4a7b 0x1a9919 0x1a99cf 0x1921bb 0x1a2b4b 0x13f2dd 0x11be6b0 0x2699fc0 0x268e33c 0x2699eaf 0x1de2bd 0x126b56 0x12566f 0x125589 0x1247e4 0x12461e 0x1253d9 0x1282d2 0x1d299c 0x11f574 0x11f76f 0x11f905 0x128917 0xec96c 0xed94b 0xfecb5 0xffbeb 0xf1698 0x1ff8df9 0x1ff8ad0 0x2012bf5 0x2012962 0x2043bb6 0x2042f44 0x2042e1b 0xed17a 0xeeffc 0x306d 0x1ef5)
libc++abi.dylib: terminate called throwing an exception
(lldb)

前もって感謝します!

4

6 に答える 6

14

ストーリーボードまたは XIB には、指定したセル識別子で定義されたセルがありません。

于 2013-04-14T00:06:49.123 に答える
5
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

  return cell; // at the end of your method 
}
于 2013-12-13T10:00:58.600 に答える
3

クラス UITableViewDelegate、UITableViewDataSource で ListaParticipantesViewController をサブクラス化しましたか? これらは、デリゲート メソッドとデータ ソース メソッドを使用できるようにするために必要です。

スウィフトの場合:

class ListaParticipantesViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
}
于 2016-09-17T20:30:19.917 に答える
2

まったく同じエラーが発生しました。セル識別子を見つけることができなかったのは同じ問題でしたが、別の理由であることがわかりました.UITableViewCellをサブクラス化していましたが、.XIBファイルをUITableViewに登録していませんでした。

viewDidLoad で resgitering することで解決しました

- (void)viewDidLoad {
  [super viewDidLoad];

  //LOAD XIB
  UINib *nib = [UINib nibWithNibName:@"NAME_OF_NIB_FILE"
                              bundle:nil];

  //REGISTER XIB, CONTAINING THE CELL (IDENTIFIER NAME USUALLY SAME AS NIB NAME)
  [[self tableView] registerNib:nib
         forCellReuseIdentifier:@"IDENTIFIER_NAME"]; 
}

そして、セルを作成します

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

  //GET THE RECYCLED CELL
  TableCellSubclass *cell = [tableView dequeueReusableCellWithIdentifier:@"IDENTIFIER_NAME"];

  //CONFIGURE THE CELL

  return cell;
}

これが誰かを助けることを願っています!

于 2013-12-16T11:48:47.153 に答える
0

私の場合、単純な間違いがありました..

私の行数はarray.countによって定義されました。

この配列を更新すると、すべてのオブジェクトが削除され、接続が開始され、オブジェクトが配列に追加され、テーブルビューが再ロードされました。

接続が完了したら、オブジェクトを削除して問題を解決しました。

于 2015-10-26T14:35:00.270 に答える