0

こんにちは!

そのウェブサイトからアプリを作成しようとしました: http://www.appcoda.com/customize-table-view-cells-for-uitableview/

そこで、各セルに 1 つのレシピがあるように、レシピを含むテーブルを作成しました。合計 16 個のセル/レシピがあります。

問題があります。アプリを実行しようとすると、次の 2 つのエラーが発生します。

1)

2012-08-09 21:12:17.332 Simple table[8886:f803] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle </Users/.../Library/Application Support/iPhone Simulator/5.1/Applications/1BA2DE48-7DEB-4564-BA33-A709412EB582/Simple table.app> (loaded)' with name 'SimpleTableCell''
*** First throw call stack:
(0x14b5022 0xeb5cd6 0x145da48 0x145d9b9 0x239638 0x23aeb7 0x23c8 0xb2c54 0xb33ce 0x9ecbd 0xad6f1 0x56d42 0x14b6e42 0x1d86679 0x1d90579 0x1d154f7 0x1d173f6 0x1da4160 0x16e84 0x17767 0x26183 0x26c38 0x1a634 0x139fef5 0x1489195 0x13edff2 0x13ec8da 0x13ebd84 0x13ebc9b 0x16c65 0x18626 0x1d1d 0x1c85)
terminate called throwing an exception(lldb) 

2)

Incompatible pointer types returning 'SimpleTableCell*_strong' from a function with result type 'UITableViewCell *'

ここで、そのポインターセルはエラーを出します:

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

    SimpleTableCell *cell = (SimpleTableCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];

    if (cell == nil)
    {
        NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"SimpleTableCell" owner:self options:nil];
        cell = [nib objectAtIndex:0];
    }

    cell.nameLabel.text = [tableData objectAtIndex:indexPath.row];
    cell.thumbnailImageView.image = [UIImage imageNamed:[thumbnails objectAtIndex:indexPath.row]];
    cell.prepTimeLabel.text = [prepTime objectAtIndex:indexPath.row];

    return cell;
}

完全なファイル (Simple_tableViewController.m)

#import "Simple_tableViewController.h"
#import "SimpleTableCell.h"

@interface Simple_tableViewController ()

@end

@implementation Simple_tableViewController

{
    NSArray *tableData;
    NSArray *thumbnails;
    NSArray *prepTime;
}

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

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

    SimpleTableCell *cell = (SimpleTableCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];

    if (cell == nil)
    {
        NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"SimpleTableCell" owner:self options:nil];
        cell = [nib objectAtIndex:0];
    }

    cell.nameLabel.text = [tableData objectAtIndex:indexPath.row];
    cell.thumbnailImageView.image = [UIImage imageNamed:[thumbnails objectAtIndex:indexPath.row]];
    cell.prepTimeLabel.text = [prepTime objectAtIndex:indexPath.row];

    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 78;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.

    // Initialize table data
    tableData = [NSArray arrayWithObjects:@"Egg Benedict", @"Mushroom Risotto", @"Full Breakfast", @"Hamburger", @"Ham and Egg Sandwich", @"Creme Brelee", @"White Chocolate Donut", @"Starbucks Coffee", @"Vegetable Curry", @"Instant Noodle with Egg", @"Noodle with BBQ Pork", @"Japanese Noodle with Pork", @"Green Tea", @"Thai Shrimp Cake", @"Angry Birds Cake", @"Ham and Cheese Panini", nil];

    // Initialize thumbnails
    thumbnails = [NSArray arrayWithObjects:@"egg_benedict.jpg", @"mushroom_risotto.jpg", @"full_breakfast.jpg", @"hamburger.jpg", @"ham_and_egg_sandwich.jpg", @"creme_brelee.jpg", @"white_chocolate_donut.jpg", @"starbucks_coffee.jpg", @"vegetable_curry.jpg", @"instant_noodle_with_egg.jpg", @"noodle_with_bbq_pork.jpg", @"japanese_noodle_with_pork.jpg", @"green_tea.jpg", @"thai_shrimp_cake.jpg", @"angry_birds_cake.jpg", @"ham_and_cheese_panini.jpg", nil];

    //initialize prep time
    prepTime=[NSArray arrayWithObjects:@"60", @"45", @"30", @"20", @"15", @"10", nil];
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}

@end

「セル」ポインターが「SimpleTableCell*_strong」型を返すのはなぜですか?また、最初のエラーが発生するのはなぜですか?

どうもありがとう!

4

1 に答える 1

1

xib をロードできないことについては肯定的ではありませんが、SimpleTableCell.h クラス定義で UITableViewCell をサブクラス化するのを忘れていたと思います。これにより、誤った戻り値を取得している理由が説明されます。これにより、ペン先をロードできない問題も解決される可能性があります。

そうでない場合は、nib ファイルの名前が、ファイルにロードされているものとまったく同じであることを確認してください。ファイルのスペルが間違っていると、この問題が発生する可能性があります。

于 2012-08-09T17:40:05.110 に答える