1

UIViewController にカスタム TableView を表示しようとしていますが、「UITableView dataSource は tableView:cellForRowAtIndexPath からセルを返す必要があります:」というエラーが表示されます。

TableView をデータソースとデリゲートに接続しました。

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

    static NSString *CellIdentifier = @"Custom";

    Custom *cell = (Custom *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil)
    {

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

         for (id currentObject in topLevelObjects)
        {

            if ([currentObject isKindOfClass:[Custom class]])
            {
                cell = (Custom *) currentObject;
                 break;
            } 
        }  
     }

     cell.textLabel.text =[arr objectAtIndex:indexPath.row];

助けてください

4

3 に答える 3

2

ここに画像の説明を入力 ここに画像の説明を入力


#import <UIKit/UIKit.h>

@interface VocaTableCell : UITableViewCell 
{
    UILabel *vocaLabel;
}
@property (nonatomic, retain) IBOutlet UILabel *vocaLabel;

@end

#import "VocaTableCell.h"


@implementation VocaTableCell
@synthesize vocaLabel;

- (void)dealloc {
    [vocaLabel release];
    [super dealloc];
}
@end

あなたのコードは間違っています。以下のコードはplzを参照してください。訂正しました。

以下のコードは、前に参照してください。customTableCell を正しく作成していますか? 以下のリストをチェックしてください。

customTablecell について作成する方法はいくつかあります。

私のやり方はとても人気があります。

  1. File's Owner の CustomTabelCell はNSObjectである必要があります。(非常に重要なデフォルトは多分UITableCellです。ファイルの所有者NSObjectを変更する必要があります(NSObjectの意味はidタイプです!))

  2. CustomTableCell はオブジェクト クラスを CustomTableCell クラスにリンクします。

  3. 参照アウトレット リンクはファイルの所有者ではありません。CustomTableCell に直接リンクする必要があります。


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

    static NSString *CellIdentifier = @"Custom";

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

    if (!cell)
    {
        UINib *nib = [UINib nibWithNibName:@"Custom" bundle:nil];
        NSArray *arr = [nib instantiateWithOwner:nil options:nil];
        cell = [arr objectAtIndex:0];
    }

    cell.textLabel.text =[arr objectAtIndex:indexPath.row];
}
于 2011-10-10T13:34:55.727 に答える
0

メソッドの最後に作成されたセルを返していないようです。「リターンセル;」を追加 最後に、エラーは消えます。

于 2011-10-10T13:12:54.913 に答える
0

returnステートメントを追加しましたか?Custom は UITableViewCell のサブクラスですか?

于 2011-10-10T13:12:59.127 に答える