0

したがって、シミュレーターを実行すると、次のようになります。

2013-01-28 13:35:38.271 Gas Index[79343:11303] -[Gas isEqualToString:]: unrecognized selector sent to instance 0x71a2260
2013-01-28 13:35:38.274 Gas Index[79343:11303] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Gas isEqualToString:]: unrecognized   selector sent to instance 0x71a2260'

これが私の ViewController.m コードです。どんな助けでも大歓迎です。(私はxcodeの初心者です)

#import "ViewController.h"
#import "DetailViewController.h"


@interface ViewController ()

@end

@implementation ViewController {
    NSArray *gases;
}

@synthesize tableView;

- (void)viewDidLoad
{
    [super viewDidLoad];

    Gas *gas1 = [Gas new];
    gas1.name=@"Argon";
    gas1.desc=@"An Inert Gas,Ar";

    Gas *gas2 = [Gas new];
    gas2.name=@"Carbon Dioxide";
    gas2.desc=@"An Inert Gas, CO2";

    Gas *gas3 = [Gas new];
    gas3.name=@"Nitrogen";
    gas3.desc=@"An Inert Gas, N2";

    gases = [NSArray arrayWithObjects:gas1,gas2,gas3, nil];

}

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

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

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

    UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];

    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
    }
    cell.textLabel.text = [gases objectAtIndex:indexPath.row];
    return cell;
}

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    if ([segue.identifier isEqualToString:@"showGasDetail"]) {
        NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
        DetailViewController *destViewController = segue.destinationViewController;
        destViewController.gas = [gases objectAtIndex:indexPath.row];
    }
}
@end
4

1 に答える 1

2

問題は次の行にあります。

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

そのコードを分割します。

Gas *gas = gases[indexPath.row];
cell.textLabel.text = gas;

それがあなたがやろうとしていることです。Gasを期待するプロパティにオブジェクトを割り当てることはできませんNSString。おそらくこれが必要です:

Gas *gas = gases[indexPath.row];
cell.textLabel.text = gas.name;

デバッガーでこれを実行すると、このエラーが発生している行を正確に示すスタック トレースが表示されることに注意してください。

于 2013-01-28T19:10:27.287 に答える