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

时间:2012-10-05 13:39:54

标签: ios variables compiler-errors iboutlet

当我运行我的应用程序时,我收到此错误:

    Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-
     [UIRoundedRectButton copyWithZone:]: unrecognized selector sent to instance
     0xcc86970'

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

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

在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];
   }

提前致谢

2 个答案:

答案 0 :(得分:12)

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

答案 1 :(得分:1)

删除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;