2011-11-19 27 views
2

我在使用一些UIButton在我的選項卡欄應用程序中調用操作時遇到問題。針對UIButton的IBAction導致無法識別的選擇器發送到實例錯誤(iOS)

我.h文件中:

#import <UIKit/UIKit.h> 

@interface ContactViewController : UIViewController { 
    UIButton *callTollFreeButton; 
    UIButton *callLocalButton; 
    UIButton *emailButton; 
} 

@property (nonatomic, retain) IBOutlet UIButton *callTollFreeButton; 
@property (nonatomic, retain) IBOutlet UIButton *callLocalButton; 
@property (nonatomic, retain) IBOutlet UIButton *emailButton; 

-(IBAction)callPhone:(id)sender; 
-(IBAction)callTollFree:(id)sender; 
-(IBAction)clickEmailButton:(id)sender; 
@end 

我.m文件:

#import "ContactViewController.h" 

@implementation ContactViewController 
@synthesize callLocalButton,callTollFreeButton,emailButton; 

-(IBAction)callPhone:(id)sender { 
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel:7576236600"]]; 
} 

-(IBAction)callTollFree:(id)sender{ 
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel:8003334645"]]; 
} 

-(IBAction)clickEmailButton:(id)sender{ 
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"mailto:[email protected]?subject=Hello"]];  
} 

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 
{ 
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 
if (self) { 
    // Custom initialization 
    } 
return self; 
} 

- (void)dealloc 
{ 
[callLocalButton release]; 
[callTollFreeButton release]; 
[emailButton release]; 
[super dealloc]; 
} 

- (void)didReceiveMemoryWarning 
{ 
// Releases the view if it doesn't have a superview. 
[super didReceiveMemoryWarning]; 

// Release any cached data, images, etc that aren't in use. 
} 

#pragma mark - View lifecycle 

- (void)viewDidLoad 
{ 
[super viewDidLoad]; 
// Do any additional setup after loading the view from its nib. 
} 

- (void)viewDidUnload 
{ 
[super viewDidUnload]; 
// Release any retained subviews of the main view. 
// e.g. self.myOutlet = nil; 
} 

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
// Return YES for supported orientations 
return (interfaceOrientation == UIInterfaceOrientationPortrait); 
} 

@end 

我.m文件:

該錯誤消息我得到的是(我得到錯誤信息任何按鈕點擊,特別是點擊電子郵件按鈕):

2011-11-19 18:39:38.786 Miller Tab Bar[761:207] -[UIViewController clickEmailButton:]: unrecognized selector sent to instance 0x6b29f40 
2011-11-19 18:39:38.790 Miller Tab Bar[761:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIViewController clickEmailButton:]: unrecognized selector sent to instance 0x6b29f40' 

我試圖連接並重新連接到視圖控制器上的對象的插座和操作。它是否可能因爲SDK無法運行測試電話或電子郵件而崩潰?

我在調試器中鍵入'po 0x6b328d0'來找出問題對象是什麼,它作爲UIViewController返回,這可能意味着View Controller在被調用之前被釋放?會導致什麼?

謝謝。


Picture of Interface Builder for ContactViewController.xib

回答

4

在你的筆尖或故事板,它看起來就像你的視圖控制器實例的類型是UIViewController而不是ContactViewController。

因此,選擇您的筆尖(或故事板)中的視圖控制器,並將其類型更改爲ContactViewController。

當然,如果這個視圖控制器沒有從一個筆尖或故事板加載,那麼只需檢查您創建它的位置,並確保您創建了正確的類的實例。

+0

我爲ContactViewController.xib(上面)添加了接口生成器的圖片,它似乎設置正確(我模糊了它,它實際上看起來不像那個哈哈)。這是你在說什麼嗎? – MillerMedia

+1

好的,你可以在代碼中加載那個筆尖嗎? –

+0

我一直在使用界面生成器,所以當我點擊一個標籤欄按鈕時,只需加載筆尖。當我點擊emailButton時,錯誤發生,而不是在加載筆尖時發生。 – MillerMedia

0

嘗試改變:

UIButton *callTollFreeButton; 
UIButton *callLocalButton; 
UIButton *emailButton; 

IBOutlet UIButton *callTollFreeButton; 
IBOutlet UIButton *callLocalButton; 
IBOutlet UIButton *emailButton; 

和鉤了UILabels各自的按鈕。看看是否有幫助。

+0

沒有改變任何東西。我已經設計了這種方法一段時間,以前它的工作,所以我不確定是否可能與視圖控制器外的代碼有關?我一直在研究調試,但找不到任何指向正確方向的東西。 – MillerMedia

+0

在設備上嘗試一下,你可能有一點關於不能在SIM上。 –

+0

我想知道如果無法識別的選擇器將是「電話:」或「mailto:」。我會繼續嘗試更深入的調試,看看它是否指向正確的方向。 – MillerMedia

0

這有點奇怪。我認爲你的viewcontroller沒有正確設置。

的離奇的部分是,你不應該能夠設置

當我一個無法識別的選擇發送至自定義視圖控制器,它說

如果沒有設置正確(文件業主 - ContactViewController)的行動

- [customViewController富]:發送到實例無法識別選擇0x6a2b440

看來廈門國際銀行的實際文件的所有者被實例化作爲一個UIViewController

相關問題