我有一個數據表,顯示聯繫人列表。當我開始選擇聯繫人後,所有的數據被加載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