2010-05-03 61 views
1

我有一個標籤和導航控制器的應用程序。UIActionSheet不顯示在視圖中,屏幕變暗

除了UIActionSheet,一切都很好。我甚至有一個UIAlertView在同一個控制器中顯示罰款,但操作表不顯示。屏幕像黑暗一樣黑暗,但沒有看到。

下面是相關代碼:

UIActionSheet *actionSheet = [[UIActionSheet alloc] 
initWithTitle:@"Erase the file?" 
delegate:self 
cancelButtonTitle:@"Cancel" 
destructiveButtonTitle:@"Clear List" 
otherButtonTitles:nil]; 
actionSheet.actionSheetStyle = UIActionSheetStyleDefault; 

[actionSheet showInView:[UIApplication sharedApplication].keyWindow]; 

//[actionSheet showInView:self.view]; 

//MyAppDelegate* delegate = [[UIApplication sharedApplication] delegate]; 
//[actionSheet showInView:delegate.tabBarController.view]; 

[actionSheet release]; 

註釋掉的代碼是顯示它的不同的方法,我試過。

任何想法,爲什麼這不工作?

回答

0

不要從當前keyWindow表現出來 - 從一些實際的標籤欄像

[actionSheet showFromTabBar:delegate.tabBarController.tabBar]; 
+0

謝謝,這工作。我會更多地閱讀爲什麼這是。當網站讓我時,我會在8分鐘內檢查答案是否正確。 – 2010-05-03 15:43:28

0

嘗試表現出來,這完美的作品:

UITextField *tempTextField; 
UIActionSheet *myActionSheet; 

- (IBAction) myDatePickerAction:(id)sender { 

    tempTextField = (UITextField *)sender; 

    [(UITextField *)sender resignFirstResponder]; 

    myActionSheet = [[UIActionSheet alloc] initWithTitle:nil 
                   delegate:self 

     cancelButtonTitle:nil 

    destructiveButtonTitle:nil 
                otherButtonTitles:nil]; 
    [myActionSheet setActionSheetStyle:UIActionSheetStyleBlackTranslucent]; 

    UIDatePicker *theDatePicker = [[UIDatePicker alloc] init]; 
    theDatePicker.datePickerMode = UIDatePickerModeDate; 
    CGRect datePickRect = theDatePicker.frame; 
    datePickRect.size.height = 120; 
    theDatePicker.frame = datePickRect; 
    [theDatePicker addTarget:self action:@selector(setDateValue:) forControlEvents:UIControlEventValueChanged]; 

     [myActionSheet addSubview:theDatePicker]; 
     [theDatePicker release]; 

    UISegmentedControl *closeButton = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObject:@"Close"]]; 
     closeButton.momentary = YES; 
     CGRect closeButtonRect = closeButton.frame; 
    closeButtonRect.size.width = 50; 
    closeButtonRect.size.height = 30; 
    closeButton.frame = closeButtonRect; 
    closeButton.segmentedControlStyle = UISegmentedControlStyleBar; 
    closeButton.tintColor = [UIColor blackColor]; 
    [closeButton addTarget:self action:@selector(dismissActionSheet:) forControlEvents:UIControlEventValueChanged]; 
    [myActionSheet addSubview:closeButton]; 
    [closeButton release]; 

    [myActionSheet showFromTabBar:appDelegate.tabBarController.tabBar]; 

    CGRect actionSheetRect = myActionSheet.bounds; 
    actionSheetRect.size.height = 300; 
    myActionSheet.bounds = actionSheetRect; 

} 

- (IBAction)setDateValue:(id)sender { 
    NSDateFormatter *myDateFormatter = [[[NSDateFormatter alloc] init] autorelease]; 
    [myDateFormatter setDateFormat:@"MM/dd/yyyy"]; 

    NSLog(@"Formatted date1:%@",[myDateFormatter stringFromDate:[(UIDatePicker *)sender date]]); 

    tempTextField.text = [myDateFormatter stringFromDate:[(UIDatePicker *)sender date]]; 
    tempTextField = nil; 
} 

- (IBAction)dismissActionSheet:(id)sender { 
    [myActionSheet dismissWithClickedButtonIndex:0 animated:YES]; 
    myActionSheet = nil; 
    //[myActionSheet release]; 
//Do not release here. Just set to nil and release it in dealloc. 
} 
2
[actionSheet showInView:self.view.window];