0

テーブルビューを学習しようとしていますが、問題が発生しました。ビュー デリゲートとデータソースがストーリーボードに正しく接続されていますが、テーブル ビューを含むアプリのセクションに到達すると、次のランタイム エラーが発生します。

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UINavigationItem tableView:numberOfRowsInSection:]: unrecognized selector sent to instance

これが私の実装ファイルのチャンクです

@implementation CraftingViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 5;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{
    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = (UITableViewCell *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier]; 
    }

    cell.textLabel.text = @"Detail";

    return cell;

}

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

}
4

2 に答える 2

1

あなたのクラスはおそらくタイプのように見えtableView:numberOfRowsInSection:ますが、タイプのオブジェクトに送信されているため、そのエラーメッセージが表示されています。適切に接続されていないように見えるため、デリゲートが正しいクラスに接続されていることを確認します。UINavigationItemCraftingViewControllerUITableViewControllerCraftingViewController

于 2012-06-19T01:50:18.797 に答える
-1

データソースが nib ファイルのコントローラーである場合。

このコントローラーの割り当てを確認してください。「UIViewController」ではなく「CraftingViewController」を使用してください。

于 2013-11-02T15:30:22.643 に答える