gpt4 book ai didi

iOS模拟器报错Xcode 4.5

转载 作者:行者123 更新时间:2023-11-28 22:40:50 25 4
gpt4 key购买 nike

所以当我运行模拟器时,我得到:

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

最佳答案

问题出在这一行:

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;

请注意,当您在调试器中运行此代码时,您应该会看到一个堆栈跟踪,显示出该错误发生在哪一行。

关于iOS模拟器报错Xcode 4.5,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14569083/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com