だから私はiOS開発に不慣れで、ボタンクリックイベントを別のクラスに委任しようとしています。アラートのボタンをクリックするたびにアプリがクラッシュし、Thread_1EXC_BAD_ACCESSというエラーが表示されます。
これは私のコードです。
// theDelegateTester.h
#import <UIKit/UIKit.h>
@interface theDelegateTester : UIResponder <UIAlertViewDelegate>
- (void) alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex;
@end
実装..
// theDelegateTester.m
#import "theDelegateTester.h"
@implementation theDelegateTester
- (void) alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
NSLog(@"Delegated");
}
@end
そして、これが私のビューファイルの実装です。
#import "appleTutorialViewController.h"
#import "theDelegateTester.h"
@interface appleTutorialViewController ()
- (IBAction)tapReceived:(id)sender;
@end
@implementation appleTutorialViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)viewDidUnload
{
// Release any retained subviews of the main view.
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
- (IBAction)tapReceived:(id)sender {
theDelegateTester *newTester = [[theDelegateTester alloc] init];
UIAlertView *myAlert = [[UIAlertView alloc] initWithTitle:@"Alert!" message:@"This is a delegated alert" delegate:newTester cancelButtonTitle:@"Close" otherButtonTitles:@"Cool!", nil];
[myAlert show];
}
@end