2011-12-02 14 views
8
- (IBAction) showCatPicker { 

    if (self.catList !=nil) { 
     self.catList=nil; 
     [catList release]; 
    } 
    self.catList = [[NSMutableArray alloc] init]; 

     self.actionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:nil cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil]; 
    [self.actionSheet setActionSheetStyle:UIActionSheetStyleBlackTranslucent]; 

    CGRect pickerFrame = CGRectMake(0, 40, 0, 0); 
    if(self.catPicker == nil) {  
     self.catPicker = [[UIPickerView alloc] initWithFrame:pickerFrame]; 

     self.catPicker.showsSelectionIndicator = YES; 
     self.catPicker.dataSource = self; 
     self.catPicker.opaque = YES; 
     self.catPicker.multipleTouchEnabled = YES; 
     self.catPicker.userInteractionEnabled = YES; 
     self.catPicker.delegate = self;  
    } 

    [self.actionSheet addSubview:self.catPicker]; 

    UISegmentedControl *closeButton = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObject:@"Select"]]; 
    closeButton.momentary = YES; 
    closeButton.frame = CGRectMake(260, 7.0f, 50.0f, 30.0f); 
    closeButton.segmentedControlStyle = UISegmentedControlStyleBar; 
    closeButton.tintColor = [UIColor colorWithRed:19.0/255 green:122.0/255 blue:53.0/255 alpha:1.0]; 
    [closeButton addTarget:self action:@selector(dismissGenderPicker:) forControlEvents:UIControlEventValueChanged]; 

    UISegmentedControl *cancelButton = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObject:@"Cancel"]]; 
    cancelButton.momentary = YES; 
    cancelButton.frame = CGRectMake(10, 7.0f, 50.0f, 30.0f); 
    cancelButton.segmentedControlStyle = UISegmentedControlStyleBar; 
    cancelButton.tintColor = [UIColor colorWithRed:19.0/255 green:122.0/255 blue:53.0/255 alpha:1.0]; 
    [cancelButton addTarget:self action:@selector(cancelActionSheet) forControlEvents:UIControlEventValueChanged]; 

    [self.actionSheet addSubview:cancelButton]; 
    [self.actionSheet addSubview:closeButton]; 

    [cancelButton release]; 
    [closeButton release]; 
    [self.actionSheet showInView:self.view];  
    [self.actionSheet setBounds:CGRectMake(0, 0, 320, 485)]; 
    [catPicker reloadComponent:0]; 
} 

उत्तर

1
self.view.userInteractionEnabled = NO; 
    self.blurView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 
    [self.blurView setBackgroundColor:[UIColor lightGrayColor]]; 
    [self.blurView setAlpha:0.3]; 
    [[[UIApplication sharedApplication] delegate].window addSubview:self.blurView]; 

    CGRect pickerFrame = CGRectMake(0, 40, 0, 0); 
    UIDatePicker *pickerView = [[UIDatePicker alloc] initWithFrame:pickerFrame]; 
    pickerView.datePickerMode = UIDatePickerModeDate; 
    [pickerView setBackgroundColor:[UIColor whiteColor]]; 
    [pickerView addTarget:self action:@selector(pickerChanged:) forControlEvents:UIControlEventValueChanged]; 

    __block CGRect frame = CGRectMake(0, [[UIScreen mainScreen] bounds].size.height, [[UIScreen mainScreen] bounds].size.width, 220); 
    self.viewForPicker = [[UIView alloc] initWithFrame:frame]; 
    [self.viewForPicker setBackgroundColor:[UIColor whiteColor]]; 
    [self.viewForPicker addSubview:pickerView]; 
    [[[[UIApplication sharedApplication] delegate] window] addSubview:self.viewForPicker]; 

    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; 
    [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; 
    [button setTitleColor:[UIColor lightGrayColor] forState:UIControlStateHighlighted]; 
    [button setTitle:@"Done" forState:UIControlStateNormal]; 
    [button addTarget:self action:@selector(doneButtonPressed:) forControlEvents:UIControlEventTouchUpInside]; 
    [button setFrame:CGRectMake(250, 15, 60, 30)]; 
    [button.layer setCornerRadius:5.0]; 
    [button.layer setBorderWidth:1.0]; 
    [button.layer setBorderColor:[[IMAppStyle appColor] CGColor]]; 
    [self.viewForPicker addSubview:button]; 
    [self.viewForPicker.layer setCornerRadius:8.0]; 

    float animationDuration = 0.25; 
    [UIView animateWithDuration:animationDuration animations:^{ 
     frame.origin.y -= (180+40+35); 
     [self.viewForPicker setFrame:frame]; 
    }]; 
3

आप निश्चित रूप से नहीं UIActionSheet का उपयोग एक UIDatePicker धारण करने के लिए चाहिए, क्योंकि इस कार्यक्षमता का बहिष्कार कर रहा है!

Documentation से:

उपवर्गीकरण नोट्स

UIActionSheet subclassed जा करने के लिए नहीं बनाया गया है, और न ही आप अपने पदानुक्रम के विचारों जोड़ना चाहिए। यदि आपको UIActionSheet API द्वारा प्रदान किए गए अनुकूलन के साथ एक शीट प्रस्तुत करने की आवश्यकता है, तो आप स्वयं बना सकते हैं और वर्तमान दृश्य नियंत्रक के साथ इसे सामान्य रूप से प्रस्तुत कर सकते हैं: एनिमेटेड: समापन:।

और

महत्वपूर्ण: UIActionSheet आईओएस 8. में पदावनत किया गया है (ध्यान दें कि UIActionSheetDelegate भी मान्य नहीं है।) बना सकते हैं और iOS 8 में कार्रवाई का प्रबंधन चादरें करने के लिए और बाद में, बजाय एक साथ UIAlertController का उपयोग UIAlertControllerStyleActionSheet की पसंदीदा स्टाइल।

क्या आप बहुत आसानी से कर सकता है एक UIView UIDatePicker पकड़ और उचित रूप में देखें चेतन करने के लिए तैयार करना है। यदि आपको आवश्यकता हो तो आप इसमें एक यूआईटीूलबार भी जोड़ सकते हैं।

दो गुण बनाएँ::

यहाँ एक उदाहरण है

@property (strong, nonatomic) UIDatePicker *theDatePicker; 
@property (strong, nonatomic) UIView *pickerView; 

अपने पिकर बनाएँ, UIView और शो में एम्बेड:

-(void) createDatePickerAndShow { 

     UIToolbar *controlToolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, pickerView.bounds.size.width, 44)]; 

     [controlToolbar sizeToFit]; 

     UIBarButtonItem *spacer = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil]; 

     UIBarButtonItem *setButton = [[UIBarButtonItem alloc] initWithTitle:@"Set" style:UIBarButtonItemStyleDone target:self action:@selector(dismissDateSet)]; 

     UIBarButtonItem *cancelButton = [[UIBarButtonItem alloc] initWithTitle:@"Cancel" style:UIBarButtonItemStyleBordered target:self action:@selector(cancelDateSet)]; 

     [controlToolbar setItems:[NSArray arrayWithObjects:spacer, cancelButton, setButton, nil] animated:NO]; 


     [theDatePicker setFrame:CGRectMake(0, controlToolbar.frame.size.height - 15, theDatePicker.frame.size.width, theDatePicker.frame.size.height)]; 

     if (!pickerView) { 
      pickerView = [[UIView alloc] initWithFrame:theDatePicker.frame]; 
     } else { 
      [pickerView setHidden:NO]; 
     } 


     CGFloat pickerViewYpositionHidden = self.view.frame.size.height + pickerView.frame.size.height; 

     CGFloat pickerViewYposition = self.view.frame.size.height - pickerView.frame.size.height; 

     [pickerView setFrame:CGRectMake(pickerView.frame.origin.x, 
             pickerViewYpositionHidden, 
             pickerView.frame.size.width, 
             pickerView.frame.size.height)]; 
     [pickerView setBackgroundColor:[UIColor whiteColor]]; 
     [pickerView addSubview:controlToolbar]; 
     [pickerView addSubview:theDatePicker]; 
     [theDatePicker setHidden:NO]; 


     [self.view addSubview:pickerView]; 

     [UIView animateWithDuration:0.5f 
         animations:^{ 
          [pickerView setFrame:CGRectMake(pickerView.frame.origin.x, 
                  pickerViewYposition, 
                  pickerView.frame.size.width, 
                  pickerView.frame.size.height)]; 
         } 
         completion:nil]; 

    } 

And to dismiss the DatePicker: 

    -(void) cancelDateSet {  
    CGFloat pickerViewYpositionHidden = self.view.frame.size.height + pickerView.frame.size.height;  

     [UIView animateWithDuration:0.5f 
         animations:^{ 
          [pickerView setFrame:CGRectMake(pickerView.frame.origin.x, 
                  pickerViewYpositionHidden, 
                  pickerView.frame.size.width, 
                  pickerView.frame.size.height)]; 
         } 
         completion:nil]; 
    } 
+2

बिल्कुल सही है, मैं आपसे सहमत हूँ क्योंकि आईओएस 8 अब UIActionSheet में सबव्यू जोड़कर मना कर देता है और एक मोडल खाली दृश्य प्रदर्शित करता है जिसे आपके ऐप से खारिज नहीं किया जा सकता है, जब तक कि आप इसे मार नहीं देते! – cdescours

+0

तो क्या यह काम करना चाहिए? कहीं कुछ गलत कर सकते हैं, लेकिन मुझे स्क्रीन पर कुछ भी नहीं मिलता है। – Moelbeck

संबंधित मुद्दे