タブ バー アプリケーションでいくつかの UIButton を使用してアクションを呼び出すのに問題があります。
私の .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@email.com?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'
View Controllerのオブジェクトにアウトレットとアクションを接続して再接続しようとしました。SDK がテスト用の電話や電子メールを実行できないためにクラッシュする可能性はありますか?
デバッガーに「po 0x6b328d0」と入力して、問題のオブジェクトが何であるかを調べたところ、UIViewController として返されました。これは、アクションが呼び出される前にビュー コントローラーが解放されたことを意味している可能性があります。何が原因でしょうか?
ありがとう。