1

チュートリアルのいくつかの手順に従って、50行の単純なTableViewを作成しましたが、「Signal SIGABRT」が表示されます:/ストーリーボードのTableViewを、作成したTableViewController-Classに接続しました。

これが私の簡単なコードです:

#import "TableViewController.h"

@interface TableViewController ()

@end

@implementation TableViewController

- (id)initWithStyle:(UITableViewStyle)style
{
    self = [super initWithStyle:style];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];

    // Uncomment the following line to preserve selection between presentations.
    // self.clearsSelectionOnViewWillAppear = NO;

    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

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

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

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

    // Configure the cell...

    cell.textLabel.text = [NSString stringWithFormat:@"Row %i",indexPath.row];

    return cell;
}
4

1 に答える 1

2

スタック オーバーフローへようこそ! sを設定するための標準的な方法はUITableViewCell、少し前に少し変更されました。これは、Xcode が提供する tableViews 用のテンプレート コードが-tableView: dequeueReusableCellWithIdentifier: forIndexPath:メソッドを使用しているのに対し、古いチュートリアルや本 (それらのほとんど) が使用していることを意味します。tableView: dequeueReusableCellWithIdentifier:

新しい方法 ( -tableView: dequeueReusableCellWithIdentifier: forIndexPath) を追加する必要がある場合は、 を追加する必要があります [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"Cell"];(viewDidLoadまたは、ストーリーボード/ニブでプロトタイプ セルの再利用 ID を設定し、セル タイプを適切に設定します - 基本は通常のセルに対して行う必要があります)。

古い方法 ( tableView: dequeueReusableCellWithIdentifier:) の後には通常、次のifようなステートメントが続きます。

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

\\Configure the cell. . .コメントの場所)

これは非常に簡単なことですが、公平を期すために、ほとんどのチュートリアルは古い方法を教えているため、2 つの方法の小さな違いに気付かないと、初心者が混乱する可能性があると思います-tableView:dequeueReusableCell。新しい方法を示すチュートリアルはこちら

于 2013-02-10T20:47:52.703 に答える