How to check alertview values
This is my code :
self.myAlert = [[[UIAlertView alloc] initWithTitle:@"MNB" message:@"R u want to delete" delegate:self cancelButtonTitle:@"OK",nil otherButtonTitles:@"Cancel",nil] autorelease];
[myA开发者_运维百科lert show];
Here I would like to process if OK button click and also for cancel button, I would like to redirect the page if OK button clicked....I need the coding, IF condition statement when OK button clicked.....pls help me....
Read UIAlertViewDelegate Protocol Reference.
You can implement following methods.
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
Just need to write the Delegate method of UIAlertView like this
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
if(buttonIndex==1){
NSLog(@"Cancelled Clicked");
}
if(buttonIndex==0){
NSLog(@"O.K Clicked");
}
}
Will surely work :)
You can use UIAlertView delegate methods. For example
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
{
if(buttonIndex == 0) //your OK button
{
//Some code here
}
else if(buttonIndex == 1)
{
//Some other code
}
}
精彩评论