我遇到了一个问题,UIAlertViewDelegate方法- (void)alertViewCancel:(UIAlertView *) AlertView 在取消带有cancel按钮的AlertView时没有被调用。
奇怪的是委托方法- (void)alertView:(UIAlertView *)alertView alertView非常有效。
有谁有主意吗?
提前感谢
肖恩
- (void)alertViewCancel:(UIAlertView *)alertView
{
if(![self aBooleanMethod])
{
exit(0);
}
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
//some code
} 当一个按钮被点击时,我称之为:
- (void)ImagePickDone
{
UIAlertView *alertDone = [[UIAlertView alloc]
initWithTitle:@"Done"
message:@"Are u sure?"
delegate:self
cancelButtonTitle:@"Cancel"
otherButtonTitles: @"Yes", nil];
[alertDone show];
[alertDone release];
}发布于 2010-03-15 15:50:16
alertViewCancel用于系统关闭警报视图时,而不是当用户按下“取消”按钮时。来自苹果文档的报价
或者,您可以实现alertViewCancel:方法,以便在系统取消警报视图时采取适当的操作。如果委托不实现此方法,则默认行为是模拟用户单击“取消”按钮并关闭视图。
如果您想在用户按下“取消”按钮时捕获,则应该使用clickedButtonAtIndex方法并检查索引是否对应于“取消”按钮的索引。要获得此索引,请使用:
index = alertDone.cancelButtonIndex;发布于 2010-03-16 15:18:22
可以在此委托的索引0处处理Cancel:
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex == 0){
//cancel button clicked. Do something here.
}
else{
//other button indexes clicked
}
} 发布于 2013-10-17 18:49:29
这可以通过两种方式加以改进。首先,它只处理用户实际单击按钮的情况。它不处理myAlert dismissWithClickedButtonIndex:被调用的情况,也不处理以其他方式解除警报的情况。其次,按钮0不一定是“取消”按钮。在有两个按钮的警报中,左边的是索引0,右边的是索引1。如果您更改标题,使右按钮显示“取消”,那么按钮1在逻辑上就是“取消”按钮。您可以实现"willDismiss“而不是"didDismiss”,该“didDismiss”将在对话框消失后调用,而不是在之前。
- (void)alertView:(UIAlertView *)alertView willDismissWithButtonIndex:(NSInteger)buttonIndex
{
if (buttonIndex == alertView.cancelButtonIndex)
{
//cancel button clicked. Do something here.
}
else
{
//other button indexes clicked
}
} https://stackoverflow.com/questions/2448244
复制相似问题