如何使用父视图控制器启动uiactionsheet以使其不被剪裁?

时间:2012-04-28 22:46:11

标签: iphone ios

嘿所以我有一个问题,我将动作表插入到不同视图控制器中的scrollview内部的视图中。动作表工作得很好,问题是如果我在滚动视图中完全停下来,动作表将被剪掉。我试过几个没有运气的解决方案。我认为问题是将动作表插入到放置在scrollview中的视图中。任何人都知道如何从视图控制器启动滚动视图所在的操作表?以下是我现在尝试的方法:

当触摸按钮时,它会调用此方法:

- (IBAction)callDP:(id)sender {

    UIButton *selectedButton = (UIButton *)sender;

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

    [actionSheet setActionSheetStyle:UIActionSheetStyleBlackTranslucent];

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

    datePickerView = [[UIDatePicker alloc] initWithFrame:pickerFrame];
    datePickerView.tag = 10;

    [datePickerView addTarget:self action:@selector(changeDate:)   forControlEvents:UIControlEventValueChanged];

    [actionSheet addSubview:datePickerView];
    [actionSheet setTitle:@"Start Date"];        
    UISegmentedControl *closeButton = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObject:@"Done"]];
    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];


    datePickerView.datePickerMode = UIDatePickerModeDate;


   //THIS IS THE PART THAT I THINK I AM HAVING THE PROBLEM WITH 

   // [actionSheet showFromToolbar:self.toolbarItems];
    //[actionSheet showFromTabBar:self.parentViewController.tabBarController.tabBar];
    [actionSheet showInView:self.parentViewController.view];


}

这是我将视图插入scrollview的地方。我设置它,以便我使用来自不同的uiviewcontroller类的视图来控制所有内容。我这样做的原因是我可以拥有可滚动的部分,但能够直观地创建我需要的所有内容而无需以编程方式执行....我很抱歉,如果这有点令人困惑。我可以澄清是否需要...但是现在是。包含我想要放入滚动视图的视图的viewcontroller类称为注册页面。它在registrationPage里面调用actionSheet。让我知道你的想法...

registrationPage = [[RegistrationPageToInsertViewController alloc]init];

    viewToInsert = registrationPage.view;

    [scrollView addSubview:viewToInsert];
    [scrollView setContentSize:viewToInsert.frame.size];
//    [scrollView sendSubviewToBack:imgView];

    //scrollView.contentSize=CGSizeMake(320,416);
    [self.view bringSubviewToFront:scrollView];

以下是一些屏幕截图,可帮助您了解我在说什么: This is what happens when you click on the button while its at the bottom of the screen

This is what happens when i scroll down a little bit on the screen and then push the birthdate button

1 个答案:

答案 0 :(得分:1)

而不是这一行

[actionSheet showInView:self.parentViewController.view]; 

尝试这样。

[actionSheet showInView:self.view];

就像我说的那样。你有一个笔尖或viewController。随你。只需添加一个scrollView作为subView即可。然后你只需要添加所有文本字段,标签,所有这些都将是scrollView的子视图。这是正确的方法。如果你出现行动表,你必须在自己中显示。只查看。