2012-10-05 56 views
1

當我運行我的應用程序我得到這個錯誤:NSInvalidArgumentException:無法識別的選擇發送到實例

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

爲什麼我得到這樣的錯誤?我小心地檢查IBOutlets和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]; 
    } 

感謝

回答

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; 
+0

你想用這個做什麼?你能添加一些評論嗎? – Yaroslav

+0

這不足以解決崩潰 –

+0

好,但[查看如何寫一個很好的答案(http://meta.stackexchange.com/questions/7656/how-do-i-write-a-good-answer-to -a-問題)和[這裏太(http://msmvps.com/blogs/jon_skeet/archive/2009/02/17/answering-technical-questions-helpfully.aspx) – Yaroslav

相關問題