所以当我运行模拟器时,我得到:
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 的 n00b)
#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