【发布时间】:2010-04-28 21:07:09
【问题描述】:
我有一个显示联系人列表的数据表。当我启动应用程序时,所有数据都已正确加载。但选择联系人后,有时会出现此异常:-
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 = 名称; 返回单元格; }
如果我替换这些代码行
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_ACES。
我调试了代码,列表appDelegate expensivePersonsList 包含对象。谁能告诉我可能的原因?
【问题讨论】:
-
我想我找到了问题,问题出在 person 对象上,它以某种方式被释放了。但是这怎么会发生,我将这个对象传递给一个视图控制器链。
@property (nonatomic, retain) IBOutlet Person *selectedPerson;而且我不会释放这个对象的任何视图控制器。
标签: iphone