2014-05-21 59 views
0

我使用UIActionSheet從不同的UITextview中調用。 一次作爲日期選擇器和值列表。UIActionSheet與以前的值混合使用

第二次被稱爲值將與以前的值混在一起。

有人可以請幫助解決這個問題。

- (void)viewDidLoad 
{ 
    pickerViewPopup = [[UIActionSheet alloc] initWithTitle:nil 
               delegate:self 
            cancelButtonTitle:nil 
           destructiveButtonTitle:nil 
            otherButtonTitles:nil]; 
pickerView = [[UIDatePicker alloc] initWithFrame: CGRectMake(0, 44, 320, 266)]; 
catPickerView = [[UIPickerView alloc]initWithFrame:CGRectMake(0, 44, 320, 266)]; 

[super viewDidLoad]; 
} 

#pragma mark - 
#pragma mark - TextField Delegate 

- (void)textFieldDidBeginEditing:(UITextField *)aTextField{ 
[aTextField resignFirstResponder]; 

switch (aTextField.tag) { 
    case 1: 
     [self ShowDatePick]; 
     break; 

    case 3: 
     [self ShowCategoryPick]; 
     break; 
    default: 
     break; 
} 
} 

-(void) ShowDatePick{ 
pickerView.datePickerMode = UIDatePickerModeDate; 
//pickerView.hidden = NO; 
pickerView.date = [NSDate date]; 
[pickerView addTarget:self action:@selector(updateTextField:)  forControlEvents:UIControlEventValueChanged]; 
[_txtDate setInputView:pickerView]; 

UIToolbar *pickerToolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)]; 
pickerToolbar.barStyle = UIBarStyleDefault; 
[pickerToolbar sizeToFit]; 

NSMutableArray *barItems = [[NSMutableArray alloc] init]; 

UIBarButtonItem *space = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil]; 
[barItems addObject:space]; 

UIBarButtonItem *cancelBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(doneButtonPressed:)]; 
[barItems addObject:cancelBtn]; 

[pickerToolbar setItems:barItems animated:YES]; 

[pickerViewPopup addSubview:pickerToolbar]; 
[pickerViewPopup addSubview:pickerView]; 
//[self.view addSubview:pickerViewPopup]; 
[pickerViewPopup showInView:self.view]; 
[pickerViewPopup setBounds:CGRectMake(0,0,320, 464)]; 
} 

-(void) ShowCategoryPick{ 
pickerArray = [[NSArray alloc]initWithObjects:@"Chess", 
       @"Cricket",@"Football",@"Tennis",@"Volleyball", nil]; 

catPickerView.dataSource = self; 
catPickerView.delegate = self; 

UIToolbar *pickerToolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)]; 
pickerToolbar.barStyle = UIBarStyleDefault; 
[pickerToolbar sizeToFit]; 

NSMutableArray *barItems = [[NSMutableArray alloc] init]; 

UIBarButtonItem *space = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil]; 
[barItems addObject:space]; 

UIBarButtonItem *cancelBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(doneButtonPressed:)]; 
[barItems addObject:cancelBtn]; 

[pickerToolbar setItems:barItems animated:YES]; 

[pickerViewPopup addSubview:pickerToolbar]; 
[pickerViewPopup addSubview:catPickerView]; 
[pickerViewPopup showInView:self.view]; 
[pickerViewPopup setBounds:CGRectMake(0,0,320, 464)]; 
} 

Mixed up UIActionSheet

回答

0

你需要從你的pickerViewPopup刪除以前添加的子視圖添加新的人之前:

... 
[catPickerView removeFromSuperView]; 
[pickerViewPopup addSubview:pickerView]; 
... 

... 
[pickerView removeFromSuperView]; 
[pickerViewPopup addSubview:catPickerView]; 
...