Possible Duplicate:
multiple UIAlertView issue
I`am beginner ios developer. And I faced with the following problem:
In my app has one viewController with 2 UIAlertView`s. One of them has UIdatePicker, and the other has UIPickerView. In other words – they are different, with different components and various processing algorithms.
And they must has different handlers. But I don`t know, how create different handlers with “delegate:self” on one viewController.
I do so:
-(IBAction)alertDataPicker:(id)sender
{
selectPickerController *dataPicker=[[selectPickerController alloc] initWithTitle:@"" message:@"" delegate:self cancelButtonTitle:@"Отмена" otherButtonTitles:@"Сохранить", nil];
NSError *err;
NSFetchRequest *fetch = [[NSFetchRequest alloc] initWithEntityName:@"Authors"];
dataPicker.data = [self.context executeFetchRequest:fetch error:&err];
[dataPicker show];
}
-(IBAction)alertDatePicker:(id)sender
{
datePickerALertControllerViewController *pickerAlertView = [[datePickerALertControllerViewController alloc] initWithTitle:@" " message:@" " delegate:self cancelButtonTitle:@"Отмена" otherButtonTitles:@"Сохранить", nil];
pickerAlertView.datePickerView.date=[self stringToDate:createDate.text];
[pickerAlertView show];
}
#pragma mark UIAlertViewDelegate
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSLog(@"qwe");
//NSLog(@"%@",alertView.datePickerView.date);
//createDate.text =[self dateToString:alertView.datePickerView.date];
//NSLog(@"date %@...%@",date,alertView.datePickerView.date);
}
But xCode says that UIAlertView don`t has prorepty “datePickerView”
– (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
But if specify the class object that comes, then a similar problem arises with the properties of an object from another class.
How I can create a different handlers to my UIAlertView`s or can determine which class of object called this method, and depending on it to go to different algorithms?
Thanks in advance for the help and for your advice.
You need to add
tags to eachUIAlertViewto distinguish them when the delegate methods are called. See my answer here.Another way would be checking if the delegate’s
alertViewis equal to one of yourUIAlertViewcontrols: