在我的警报视图中,有两个按钮,确定和取消。当用户单击“确定”按钮时,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];
是否可以?