私のアラート ビューには、[OK] と [キャンセル] の 2 つのボタンがあります。ユーザーが [OK] ボタンをクリックすると、デリゲート メソッドdismissWithClickedButtonIndex:animated
が呼び出され、インデックスが 0 の場合、コードを実行するメソッドが呼び出されます。
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Alert"
message:@"Are you sure you want to exit"
delegate:self cancelButtonTitle: @"OK"
otherButtonTitles: @"Cancel",nil];
[alert show];
[alert release];//release the reference
委任方法:
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex{
if (buttonIndex==0) {
[self aMethod];
}
}
-(void)aMethod{
//Some useful code
}
今、私がしたいのは、これらすべての代わりに、aMethod
デリゲートメソッドと呼び出されるメソッドを参照せずに、AlertView でメソッドのコードを直接実行することです。
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Alert"
message:@"Are you sure you want to exit"
delegate:self cancelButtonTitle: @"OK" //Put here some useful code
otherButtonTitles: @"Cancel",nil];
出来ますか?