-3

私は Objective C と iOS 開発全般にかなり慣れていませんが、まだその感覚をつかもうとしています。しかし、ストーリーボードを使用してメインページとして UITableViewController を使用して (現時点では) シンプルな iOS アプリを作成しようとしています。私はちょうどセルを表示させようとしています。私のコードは次のとおりです。

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
   // Return the number of sections.
   return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
   // Return the number of rows in the section.
   return 1;
}

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

   return cell;
}

私は 2 番目の iOS バードウォッチング チュートリアル アプリ(リンク)に厳密に従っており、以前にシミュレーターで表示できるように UITableViewController を取得しました。しかし、これが野鳥観察アプリのように機能しない理由がわかりません。

私が得ているエラーは次のとおりです。

'NSInternalInconsistencyException', reason: 'UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath:

私は何を間違っていますか?

4

2 に答える 2

0

したがって、Storyboards と UITableViewController を使用しています。これは、次のことを行う必要があることを意味します。

  1. ストーリーボードに移動
  2. テーブル ビューの最初のセルをクリックします。
  3. ユーティリティ (右側のウィンドウ) が表示されていることを確認します
  4. 属性インスペクターをクリックします
  5. 「スタイル」を「カスタム」から「基本」に変更します (セルをカスタマイズした場合はカスタムを使用します)。
  6. 識別子をクリックし、cellForRowAtIndexPath メソッド (cervical_patterns) と同じであることを確認します。

クラスが正しく設定されていることも確認してください。

  1. ストーリーボードに移動
  2. テーブル ビューの下にある黒いバーをクリックします。
  3. ユーティリティ (右側のウィンドウ) が表示されていることを確認します
  4. ID インスペクタをクリックします。
  5. カスタムクラスがドロップダウンで選択されていることを確認してください

これを XCode で実行したところ、完全に機能しました (コードは不要であることに注意してください) (cell == nil)以下の正確なコード:

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    // Return the number of sections.
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    // Return the number of rows in the section.
    return 1;
}

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

    // Configure the text and graphics of the cell

    return cell;
}
于 2012-09-12T14:17:53.920 に答える
-1

次のように、実際にセルを作成する必要があります。

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

    if (cell == nil) {
       cell = [[[UITableViewCell alloc]
               initWithStyle:UITableViewCellStyleDefault
             reuseIdentifier:cervical_patterns ] autorelease];

    }

   return cell;
}
于 2012-09-11T01:03:00.210 に答える