为了账号安全,请及时绑定邮箱和手机立即绑定

添加UIPickerView&动作表中的按钮-如何添加?

添加UIPickerView&动作表中的按钮-如何添加?

ibeautiful 2019-07-12 16:36:18
添加UIPickerView&动作表中的按钮-如何添加?我的应用程序要求在操作表中添加以下内容。UIToolbarUIToolbar上的按钮UIPicker控制我已经包括了一个图像,以了解我的要求。请你解释一下,这是如何实现的?
查看完整描述

3 回答

?
GCT1015

TA贡献1827条经验 获得超4个赞

iOS 7的最新情况

用于UIActionSheet的苹果文档UIActionSheet is not designed to be subclassed, nor should you add views to its hierarchy

我建议不要尝试自定义ActionSheet的内容,因为它会导致IOS 7中严重的无效上下文错误。我只是花了几个小时来解决这个问题,最终决定采取不同的方法。我将调用替换为使用包含简单表视图的模态视图控制器来显示操作表。

要做到这一点,有很多种方法。下面是我在当前项目中实现的一种方法。这很好,因为我可以在5到6个不同的屏幕之间重用它,在这些屏幕上,我所有的用户都可以从选项列表中进行选择。

  1. 创建一个新的UITableViewController子类,

    SimpleTableViewController.

  2. 在情节提要中创建一个UITableViewController(嵌入在导航控制器中),并将其自定义类设置为SimpleTableViewController。
  3. 给SimpleTableViewController的导航控制器一个“SimpleTableVC”的故事板ID。
  4. 在SimpleTableViewController.h中,创建一个NSArray属性来表示表中的数据。
  5. 同样在SimpleTableViewController.h中,创建一个协议

    SimpleTableViewControllerDelegate

    用所需的方法

    itemSelectedatRow:

    ,以及名为类型委托的弱属性。

    id<SimpleTableViewControllerDelegate>

    ..这就是我们将选择传递回父控制器的方式。
  6. 在SimpleTableViewController.m中,实现tableview数据源和委托方法,调用

    itemSelectedatRow:

    在……里面

    tableView:didSelectRowAtIndexPath:.

这种方法具有相当可重用的额外好处。若要使用,请在ViewController.h中导入SimpleTableViewController类,遵循SimpleTableViewDelegate,并实现itemSelectedAtRow:方法。然后,要打开该模型,只需实例化一个新的SimpleTableViewController,设置表数据和委托,并呈现它。

UINavigationController *navigationController = (UINavigationController *)[self.storyboard instantiateViewControllerWithIdentifier:
@"SimpleTableVC"];SimpleTableViewController *tableViewController = (SimpleTableViewController *)[[navigationController viewControllers]
 objectAtIndex:0];tableViewController.tableData = self.statesArray;tableViewController.navigationItem.title = @"States";
 tableViewController.delegate = self;[self presentViewController:navigationController animated:YES completion:nil];

我创建了一个简单的例子张贴在GitHub上.

亦见显示操作表会导致CGContext无效上下文错误.


查看完整回答
反对 回复 2019-07-12
  • 3 回答
  • 0 关注
  • 661 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信