我創建了一個帶有兩個按鈕的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