[英]NSInvalidArgumentException: unrecognized selector sent to instance
When I run my application I get this error: 当我运行我的应用程序时,出现以下错误:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-
[UIRoundedRectButton copyWithZone:]: unrecognized selector sent to instance
0xcc86970'
Why I get an error like this? 为什么我会收到这样的错误? I was careful to check all connection of IBOutlets e all IBAction. 我非常仔细地检查了IBOutlets和所有IBAction的所有连接。 This is my code: 这是我的代码:
MenuViewController.h MenuViewController.h
@interface MenuViewController : UIViewController
<UITableViewDelegate, UITableViewDataSource>{
}
@property (nonatomic, copy) IBOutlet UITableView * tableView;
@property (nonatomic,copy) IBOutlet UILabel *labelTitle;
@property (nonatomic, copy) IBOutlet UIButton *buttonHome;
@property (nonatomic, copy) IBOutlet UIButton *buttonMap;
@property (nonatomic, copy) IBOutlet UIButton *buttonFavorites;
-(IBAction) pressedHome:(id)sender;
-(IBAction) pressedMap: (id)sender;
-(IBAction) pressedFavorites: (id)sender;
@end
In MenuViewController.m 在MenuViewController.m中
-(IBAction) pressedHome:(id)sender{
MenuViewController * menu =[[MenuViewController alloc]initWithNibName:@"MenuViewController" bundle:nil];
[self.navigationController pushViewController:menu animated:YES];
}
-(IBAction) pressedMap: (id)sender{
MapViewController * map =[[MapViewController alloc]initWithNibName:@"MapViewController" bundle:nil];
[self.navigationController pushViewController:map animated:YES];
}
-(IBAction) pressedFavorites: (id)sender{
FavoritesViewController * favorites =[[FavoritesViewController alloc]initWithNibName:@"FavoritesViewController" bundle:nil];
[self.navigationController pushViewController:favorites animated:YES];
}
Thanks in advance 提前致谢
Remove the copy
. 删除copy
。 This is happening because UIButton (and other UIControls) don't conform to the NSCopying
protocol, so the call to copy them fails. 发生这种情况是因为UIButton(和其他UIControl)不符合NSCopying
协议,所以复制它们的调用失败。
Remove copy
for the following properties 删除以下属性的copy
@property (nonatomic) IBOutlet UITableView * tableView;
@property (nonatomic) IBOutlet UILabel *labelTitle;
@property (nonatomic) IBOutlet UIButton *buttonHome;
@property (nonatomic) IBOutlet UIButton *buttonMap;
@property (nonatomic) IBOutlet UIButton *buttonFavorites;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.