首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >NSInvalidArgumentException:发送给实例的无法识别的选择器

NSInvalidArgumentException:发送给实例的无法识别的选择器
EN

Stack Overflow用户
提问于 2012-10-05 21:39:54
回答 2查看 3.7K关注 0票数 1

当我运行我的应用程序时,我得到这个错误:

代码语言:javascript
运行
复制
    Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-
     [UIRoundedRectButton copyWithZone:]: unrecognized selector sent to instance
     0xcc86970'

为什么会出现这样的错误?我小心翼翼地检查了IBOutlets e IBAction的所有连接。这是我的代码:

MenuViewController.h

代码语言:javascript
运行
复制
     @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

在MenuViewController.m中

代码语言:javascript
运行
复制
 -(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];
   }

提前感谢

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-10-05 21:50:25

卸下copy。这是因为UIButton (和其他UIControls)不符合NSCopying协议,所以复制它们的调用失败。

票数 12
EN

Stack Overflow用户

发布于 2012-10-05 21:48:26

删除以下属性的copy

代码语言:javascript
运行
复制
@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;
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12747520

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档