2012-02-29 234 views
8

我使用this後的代碼在我的應用程序中顯示一個操作表。但它表明像iPad UIActionSheet not showing

enter image description here

會有什麼原因呢?

我的代碼顯示動作片是

UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:nil 
                 delegate:nil 
               cancelButtonTitle:nil 
              destructiveButtonTitle:nil 
               otherButtonTitles:nil]; 

[actionSheet setActionSheetStyle:UIActionSheetStyleBlackTranslucent]; 

CGRect pickerFrame = CGRectMake(0, 40, 300, 300); 

UIView *pickerView = [[UIView alloc] initWithFrame:pickerFrame]; 
pickerView.backgroundColor=[UIColor blackColor]; 

[actionSheet addSubview:pickerView]; 


UISegmentedControl *closeButton = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObject:@"Close"]]; 
closeButton.momentary = YES; 
closeButton.frame = CGRectMake(260, 7.0f, 50.0f, 30.0f); 
closeButton.segmentedControlStyle = UISegmentedControlStyleBar; 
closeButton.tintColor = [UIColor blackColor]; 
[closeButton addTarget:self action:@selector(dismissActionSheet:) forControlEvents:UIControlEventValueChanged]; 
[actionSheet addSubview:closeButton]; 


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

[actionSheet setBounds:CGRectMake(0, 0, 320, 485)]; 

[self.view addSubview:actionSheet]; 
+0

Atleast給按鈕一些標題。否則它不會出現。 – 2012-02-29 09:52:10

回答

0

使用UIActionSheet showFromRectUIActionSheet showFromBarButtonItem:方法。

UIActionSheetDelegate方法 -

- (void)showFromBarButtonItem:(UIBarButtonItem *)item animated:(BOOL)animated; 
- (void)showFromRect:(CGRect)rect inView:(UIView *)view animated:(BOOL)animated; 

例如:

[actionSheet showFromRect:self.btnShare.frame inView:self.view animated:YES]; 

如果您正在使用iPhone應用程序使用UIActionSheet showInView方法 -

- (void)showInView:(UIView *)view; 

例子 -

[actionSheet showInView:self.view.window];