我在使用一些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在被調用之前被釋放?會導致什麼?
謝謝。
我爲ContactViewController.xib(上面)添加了接口生成器的圖片,它似乎設置正確(我模糊了它,它實際上看起來不像那個哈哈)。這是你在說什麼嗎? – MillerMedia
好的,你可以在代碼中加載那個筆尖嗎? –
我一直在使用界面生成器,所以當我點擊一個標籤欄按鈕時,只需加載筆尖。當我點擊emailButton時,錯誤發生,而不是在加載筆尖時發生。 – MillerMedia