iphone - 如何使用父 View Controller 启动 uiactionsheet 使其不被剪切?

标签 iphone ios

嘿,我遇到了一个问题,我将操作表插入到位于不同 View Controller 中的 ScrollView 内部的 View 中。操作表工作得很好,问题是,如果我在 ScrollView 中完全下降,操作表就会被剪掉。我尝试了几种解决方案但没有运气。我认为问题在于操作表被插入到 ScrollView 内的 View 中。任何人都知道如何从 ScrollView 所在的 View Controller 启动操作表?这是我现在正在尝试的方法:

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

- (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];


}

这是我将 View 插入 ScrollView 的位置。我已经设置了它,以便我使用来自不同 uiviewcontroller 类的 View 来控制一切。我这样做的原因是这样我可以拥有可滚动部分,但能够直观地创建我需要的一切,而不必以编程方式完成......如果这有点令人困惑,我深表歉意。如果需要的话我可以澄清……但就是这样。包含我想要放入 ScrollView 的 View 的 View Controller 类称为注册页面。它在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

最佳答案

而不是这一行

[actionSheet showInView:self.parentViewController.view]; 

尝试这样。

[actionSheet showInView:self.view];

按照我说的做。你有一个 Nib 或 View Controller 。任何。只需将 ScrollView 添加为您所拥有的 subview 。然后您只需添加所有文本字段、标签,所有内容都将成为 ScrollView 的 subview 。这是正确的方法。如果您呈现操作表,则必须在自己中显示.仅查看。

关于iphone - 如何使用父 View Controller 启动 uiactionsheet 使其不被剪切?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10368216/

相关文章:

ios - SpriteKit 和 Swift,如果条件为真,则将平台设置为 nil 将不起作用

iphone - 将NSInteger传递给方法不起作用

ios - 我没有得到正确的信号值来识别 iPhone 和蓝牙设备之间的距离

iphone - 如何为应用程序排除第 4 代 iPod touch

ios - 如何制作像Notes应用程序一样的删除动画

objective-c - xcode 4.2 因内部错误而不断崩溃

ios - 使用 Drawrect 绘图

ios - AlamofireObjectMapper 在应该给我值(value)的时候得到了 nil

iPhone:将文本分成框架的行

iphone - 编辑时如何将图像叠加添加到UIImagePickerControllerSourceTypePhotoLibrary?