Iphone -[UITableViewRowData isEqualToString:]:发送到实例0x391dce0的选择器无法识别
我有一个显示联系人列表的数据表。启动应用程序时,所有数据都已正确加载。但在选择联系人后,有时会出现以下异常:-Iphone -[UITableViewRowData isEqualToString:]:发送到实例0x391dce0的选择器无法识别,iphone,Iphone,我有一个显示联系人列表的数据表。启动应用程序时,所有数据都已正确加载。但在选择联系人后,有时会出现以下异常:- 程序收到信号:“EXC\U坏访问”。 有时 -[UITableViewRowData isEqualToString:]:发送到实例0x391dce0的选择器无法识别 对于此代码,最可能的情况是:- -(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)
程序收到信号:“EXC\U坏访问”。
有时
-[UITableViewRowData isEqualToString:]:发送到实例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];
// 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];
Person*Person=(Person*)[appDelegate.expensivePersonsList对象索引:indexPath.row]
NSString*name=[NSString stringWithFormat:@“%@%@”,person.lastName,person.firstName]
cell.textlab.text=名称;
返回单元;
}
如果我替换这些代码行
NSString*name=[NSString stringWithFormat:@“%@%@”,person.lastName,person.firstName];
cell.textlab.text=名称;
使用此代码
cell.textlab.text=person.lastName;
那么一切正常吗
我不知道到底发生了什么?
在四处查看和调试之后,我发现这段代码似乎不起作用。
-(void)tableView:(UITableView*)tableView未选择RowatineXpath:(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];
// 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(@“%@”,人名);
丢了一个坏球。
我调试了代码,列表
appDelegate ExpensivePersonList
包含对象。有人能告诉我可能的原因吗?EXC\u BAD\u ACCESS上的调用堆栈是什么
此外,您只需使用NSString获取格式化字符串,无需使用NSMutableString或强制转换它…EXC\u BAD\u访问上的调用堆栈是什么
此外,您只需使用NSString获取格式化字符串,无需使用NSMutableString或强制转换它…我认为您需要为“objc\u exception\u throw”设置一个符号断点,以便查看崩溃前发生的情况。只需进入运行菜单->管理断点->添加符号断点,然后键入objc\u exception\u throw
顺便说一句,您可能正在调用已删除的对象 我想您应该为“objc\u exception\u throw”设置一个符号断点,以便查看崩溃前发生的情况。只需进入运行菜单->管理断点->添加符号断点,然后键入objc\u exception\u throw
顺便说一句,您可能正在调用已删除的对象 最后,我发现了问题所在。实际上,我想做的是将Person对象的所有属性设置为只读,这样只有在init方法中,属性才会被初始化。所以这个人h看起来像:
@interface Person : NSObject {
NSInteger pid;
NSString const *firstName;
NSString const *lastName;
NSString const *phoneNumber;
NSString const *emailAddress;
}
@property (readonly) NSString *firstName;
@property (readonly) NSString *lastName;
@property (readonly) NSString *phoneNumber;
@property (readonly) NSString *emailAddress;
@property (readonly) NSInteger pid;
-(id)initWithName:(NSString *)n lastName:(NSString *)l phoneNumber:(NSString *)p emailAddress:(NSString *)e pid:(NSInteger)i;
@end
所有这些值都没有保留这些值
这个问题是我所有错误的主要问题:
最后,我发现了这个问题。实际上,我想做的是将Person对象的所有属性设置为只读,这样只有在init方法中,属性才会被初始化。所以这个人h看起来像:
@interface Person : NSObject {
NSInteger pid;
NSString const *firstName;
NSString const *lastName;
NSString const *phoneNumber;
NSString const *emailAddress;
}
@property (readonly) NSString *firstName;
@property (readonly) NSString *lastName;
@property (readonly) NSString *phoneNumber;
@property (readonly) NSString *emailAddress;
@property (readonly) NSInteger pid;
-(id)initWithName:(NSString *)n lastName:(NSString *)l phoneNumber:(NSString *)p emailAddress:(NSString *)e pid:(NSInteger)i;
@end
所有这些值都没有保留这些值
这个问题是我所有错误的主要问题:
对于EXC\u BAD\u访问,控制台上没有堆栈跟踪。它只是退出说“程序接收信号:“EXC_BAD_ACCESS”。关于强制转换和NSMutableString,您是对的,我可以删除它们。但是删除它们无助于解决问题。对于EXC_BAD_ACCESS,控制台上没有堆栈跟踪。它只是退出说“程序接收信号:“EXC_BAD_ACCESS”。关于cast和NSMutableString,你是对的,我可以删除它们。但是删除它们无助于解决问题。我想我发现了问题,问题在于person对象,它不知怎么被释放了。但这怎么可能发生呢,我把这个对象传递给一系列视图控制器<代码>@property(非原子,保留)IBOutlet Person*selectedPerson代码>并且我没有释放任何ViewController。我想我发现了问题,问题在于person对象,它以某种方式被释放了。但这怎么可能发生呢,我把这个对象传递给一系列视图控制器<代码>@property(非原子,保留)IBOutlet Person*selectedPerson代码>并且我不会释放任何ViewController中的此对象。