私のiPhoneアプリには、NSObject
AクラスとUIViewController
Bクラスがあります。AからBクラスのインスタンスメソッドを呼び出したい。次のコードを使用した。
Bclass *vc = [[Bclass alloc]init];
[vc hideAlert:NSString];
[vc release];
およびBクラスの場合:
- (void)hideAlert:(NSString*)message{
UIAlertView *shareAlrt = [[UIAlertView alloc] initWithTitle:@""
message:message
delegate:self
cancelButtonTitle:@"Ok"
otherButtonTitles:nil];
[shareAlrt show];
[shareAlrt release];
}
そして、メソッドが呼び出され、AlertViewが表示されます。[OK]ボタンをクリックすると、クラスCclassに移動します。
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex == 0)
{
Cclass *vc = [[Cclass alloc]initWithNibName:@"Cclass" bundle:[NSBundle mainBundle]];
[self presentModalViewController:vc animated:NO];
[vc release];
}
}
しかし、[OK]ボタンをクリックすると、アプリがクラッシュします。ここで何が起こっているのですか?B class.hファイルに追加<UIAlertViewDelegate>
しましたが、それでも同じエラーが発生します。助けてください
エラーコードが表示されます*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFType alertView:clickedButtonAtIndex:]: unrecognized selector sent to instance 0x81baa80'