【问题标题】:Present a UIPickerView modally in a UITableViewController在 UITableViewController 中以模态方式呈现 UIPickerView
【发布时间】:2014-05-02 03:49:56
【问题描述】:

我不想在UITableViewController 的底部显示UIPickerView

问题是我不能只将选择器添加为子视图,因为它是UITableView。巴顿 tss。 UIActionSheet hack 自 iOS 7 起也无法使用,所以没有更多的想法。

有没有其他人遇到过同样的问题,可以帮我解决一下吗?

【问题讨论】:

    标签: ios uitableview uipickerview


    【解决方案1】:

    假设您尝试将其添加到 tableView 的实际底部,而不仅仅是屏幕底部,请尝试将其作为子视图添加到 Footerview。

    //Create whatever kind of pickerView here.
    
    UIView *footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.tableView.frame.size.width, self.pickerView.frame.size.height)];
    
    [footerView addSubview:self.pickerView];
    
    self.tableView.tableFooterView = footerView;
    

    如果您尝试将其添加为操作表,但在 iOS 7 上不适用于您,答案将是创建您自己的 ActionSheet 作为 UIView,其中包含 pickerView 并在您需要时动画进出.

    【讨论】:

    • 对不起。我的意思是在屏幕底部。无论如何,自定义动画将不起作用,因为您无法将其作为子视图添加到 tableView。但是到目前为止,您通过将其直接添加到主窗口中给了我最好的主意!谢谢。
    • 你的 ViewController 是一个标准的 UIViewController,里面有一个 tableview 还是一个 UITableViewController
    • 如问题所述,它是一个 UITableViewController。
    • 如果您想添加子视图,我会将其转换为 UIViewController,将其设置为您的 UITableViewDelegate/Datasource,添加 tableView,然后您可以添加任何您想要的子视图 - 动画和所有
    • 是的,我知道,但我会保留静态单元格的便利性。
    猜你喜欢
    • 2011-04-09
    • 1970-01-01
    • 2014-05-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多