2012-03-26 52 views
0

可能重复:
multiple UIAlertView issue在一个视图中的几个UIAlertView中:如何创建不同的代表

I`am初学者iOS开发者。我面临以下问题:

在我的应用程序有一个viewController与2 UIAlertView`s。其中一个具有UIdatePicker,另一个具有UIPickerView。换句话说 - 它们不同,具有不同的组件和各种处理算法。

而且他们必须有不同的处理程序。但我不知道,如何在一个viewController上创建不同的处理程序,并使用“委托:自我”。

我这样做:

-(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); 
} 

但Xcode中说,UIAlertView中不`吨有prorepty “datePickerView” - (空)alertView:(UIAlertView中*)alertView clickedButtonAtIndex:(NSInteger的)buttonIndex 但是如果指定来自另一个类的对象的属性会出现类似的问题。

如何创建一个不同的处理程序到我的UIAlertView?或者可以确定哪个类的对象称为此方法,并根据它去不同的算法?

在此先感谢您的帮助和建议。

+0

FYI:在UIAlertView中类拟用作-是,不支持子类。该类的视图层次结构是私有的,不能修改。](http://developer.apple.com/library/ios/#documentation/uikit/reference/UIAlertView_Class/UIAlertView/UIAlertView.html) – 2012-03-26 11:38:24

回答

1

您需要将tag s添加到每个UIAlertView,以在调用委托方法时区分它们。见my answer here

另一种方式将被检查,如果该委托的alertView等于你UIAlertView控件之一:

if ([alertView isEqual:myAlertView]) { ... } 
+0

谢谢,无论是这些解决方案非常简单并且看起来很明显。所有天才都很简单)) – 2012-03-26 13:56:26

相关问题