Iphone UIAlertView按钮事件问题
好的,我这里有一个小问题,我这里有这个Iphone UIAlertView按钮事件问题,iphone,objective-c,Iphone,Objective C,好的,我这里有一个小问题,我这里有这个 - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex { if (buttonIndex == 0) { //YES clicked ...do your action [self.parentViewController dismissModalViewControllerAnimated
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex == 0)
{
//YES clicked ...do your action
[self.parentViewController dismissModalViewControllerAnimated:YES];
}
else if (buttonIndex == 1)
{
//NO clicked
return;
}
}
这允许我捕获从UIAlertView按钮触发的事件,但我已为其分配了一个值,在同一页面上,我需要为该类分配另一个值,以便:
if(buttonIndex == 2){//Proceed}
我主要希望这样,当在我的第二个警报中按下按钮时,它将返回到它正在执行的进程,而不是继续执行(buttonIndex==0)事件
那么,有人知道我可以从哪里开始吗?如果你不明白这一点,你可以在程序中放置一个计数器,计算alertview被触发的次数,然后根据该值进行操作。只需在你的
.h
文件中存储一个2UIAlertView
的引用,然后进行检查。例如,在.h
文件中:
UIAlertView*alertView1;
UIAlertView*alertView2
在.m
文件中,在viewdiload
方法中设置UIAlertView
,并将alertView:ClickedButtonIndex:
方法更改为:
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex; {
if (alertView == alertView1) {
// Do what you want the alertView1 to do here.
if (buttonIndex == 0) {
//YES clicked ...do your action
[self.parentViewController dismissModalViewControllerAnimated:YES];
}
else if (buttonIndex == 1) {
}// etc.
}
else if (alertView == alertView2) {
// Do what you want the alertView2 to do here.
}
}
希望有帮助 如果应用程序中有多个alertView,则可以使用alertView标记。例如,您可以这样做:
UIAlertView *alert1 = [[UIAlertView alloc] initWithTitle:@"Title" message:@"AThe message." delegate:self cancelButtonTitle:@"button 1" otherButtonTitles: @"button 2", nil];
alert1.tag = 0;
[alert1 show];
[alert1 release];
然后在委托方法中,只需放入以下if子句:
if (alertView == alertView1)
在上面的代码之前。我不理解这个问题。。。您是否有两个不同的警报视图,并且您正试图在一个
警报视图:ClickedButtonIndex:
呼叫中找出如何区分它们?这很有帮助,谢谢大家!