2012-02-29 34 views
8

Tôi đã sử dụng mã từ this bài đăng để hiển thị một trang tính trong ứng dụng của tôi. Nhưng nó hiển thị nhưiPad UIActionSheet không hiển thị

enter image description here

Lý do là gì?

Mã của tôi để hiển thị tấm hành động là

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 cung cấp một số tiêu đề cho các nút. Nếu không nó sẽ không hiển thị. –

Trả lời

0

Sử dụng phương thức UIActionSheet showFromRect hoặc UIActionSheet showFromBarButtonItem:.

UIActionSheetDelegate phương pháp này -

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

dụ:

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

Nếu bạn đang sử dụng để sử dụng ứng dụng iPhone UIActionSheet showInView phương pháp -

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

dụ -

[actionSheet showInView:self.view.window]; 
Các vấn đề liên quan