我创建了一个带有两个按钮的UIAlertView实例,并且在我的类的接口文件(.h)中,我也设置了委托,但仍然无法在单击按钮时得到任何响应。这里是我的代码:UIAlertView委托方法不响应iOS 5.1
//myClass.h
@interface MainMenu : UIViewController<UIAlertViewDelegate>
-(IBAction)secondAct:(id)sender;
和实现
-(IBAction)secondAct:(id)sender
alert = [[UIAlertView alloc] initWithTitle:@"Dear User"
message:@"Your Request Will be Sent To Security"
delegate:nil
cancelButtonTitle:@"Cancel"
otherButtonTitles:@"OK", nil];
[alert show];
[alert autorelease];
}
和委托方法:
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
NSLog(@"UIAlertView delegate works");//this line too isnt displayed
NSString *title=[ alertView buttonTitleAtIndex:buttonIndex ];
if ([title isEqualToString:@"OK"]) {
NSLog(@"OK Pressed");
}//i want to create something like this
} 我做了所有上面的代码,但仍不能采取任何行动。无论我点击哪个按钮,都会使警报消失。这段代码有什么问题,任何人都可以帮忙? ANSWER
亲爱PeterG.评论更改delegete:nil
与delegate:self
和现在的工作。
委托:无将无法正常工作...更改为委托:自我 – 2012-03-26 14:00:40
我曾经尝试过。但它给出了一个错误 – ilhnctn 2012-03-26 14:01:28
@PeterG。对不起兄弟,它工作 – ilhnctn 2012-03-26 14:02:45