我有一个数据表,显示联系人列表。当我开始选择联系人后,所有的数据被加载correctly.But的应用,我有时会得到这个异常: -- [UITableViewRowData isEqualToString:]:无法识别的选择发送到实例0x391dce0
Program received signal: “EXC_BAD_ACCESS”.
有时
-[UITableViewRowData isEqualToString:]: unrecognized selector sent to instance 0x391dce0
最可能就是因为这个代码: -
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
ExpenseTrackerAppDelegate *appDelegate = (ExpenseTrackerAppDelegate *)[[UIApplication sharedApplication] delegate];
Person *person = (Person *)[appDelegate.expensivePersonsList objectAtIndex:indexPath.row];
NSString *name = [NSString stringWithFormat:@"%@ %@" ,person.lastName , person.firstName];
cell.textLabel.text = name; return cell; }
如果我更换这行代码
NSString *name = [NSString stringWithFormat:@"%@ %@" ,person.lastName , person.firstName]; cell.textLabel.text = name;
与此代码 cell.textLabel.text = person.lastName;
然后一切工作正常?
我不知道究竟发生了什么? 经过查看和调试后,我发现这段代码似乎不起作用。 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// RootViewController *detailViewController = [[RootViewController alloc] initWithNibName:@"RootViewController" bundle:[NSBundle mainBundle]];
PersonnalDetails *detailViewController = [[PersonnalDetails alloc] initWithNibName:@"PersonnalDetails" bundle:[NSBundle mainBundle]];
//detailViewController.view = [[UITableView alloc] initWithNibName:@"PersonnalDetails" bundle:[NSBundle mainBundle]];
// ...
// Pass the selected object to the new view controller.
ExpenseTrackerAppDelegate *appDelegate = (ExpenseTrackerAppDelegate *)[[UIApplication sharedApplication] delegate];
NSInteger row = indexPath.row;
Person *person = [[appDelegate expensivePersonsList] objectAtIndex:row];
NSLog(@"%@", person.firstName);
detailViewController.selectedPerson = person;
[self.navigationController pushViewController:detailViewController animated:YES];
[detailViewController release];
}
这一行 NSLog(@"%@", person.firstName);
抛出EXC_BAD_ACESS。 我调试了代码,列表appDelegate expensivePersonsList
包含对象。有人可以告诉我可能的原因吗?
我想我找到了问题,问题是人的对象,它就会以某种方式释放。但是,怎么会发生这种情况,我将这个对象传递给视图控制器链。
@property (nonatomic, retain) IBOutlet Person *selectedPerson;
而我不会释放这个对象的任何视图控制器。对于EXC_BAD_ACCESS, – awsome 2010-04-28 23:13:03