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

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

我的应用程序要求在操作表中添加以下内容。

  • UIToolbar
  • UIToolbar上的按钮
  • UIPicker控制

我已经包括了一个图像,以了解我的要求。

请你解释一下,这是如何实现的?


ibeautiful
浏览 664回答 3
3回答

GCT1015

iOS 7的最新情况用于UIActionSheet的苹果文档:&nbsp;UIActionSheet is not designed to be subclassed, nor should you add views to its hierarchy我建议不要尝试自定义ActionSheet的内容,因为它会导致IOS 7中严重的无效上下文错误。我只是花了几个小时来解决这个问题,最终决定采取不同的方法。我将调用替换为使用包含简单表视图的模态视图控制器来显示操作表。要做到这一点,有很多种方法。下面是我在当前项目中实现的一种方法。这很好,因为我可以在5到6个不同的屏幕之间重用它,在这些屏幕上,我所有的用户都可以从选项列表中进行选择。创建一个新的UITableViewController子类,SimpleTableViewController.在情节提要中创建一个UITableViewController(嵌入在导航控制器中),并将其自定义类设置为SimpleTableViewController。给SimpleTableViewController的导航控制器一个“SimpleTableVC”的故事板ID。在SimpleTableViewController.h中,创建一个NSArray属性来表示表中的数据。同样在SimpleTableViewController.h中,创建一个协议SimpleTableViewControllerDelegate用所需的方法itemSelectedatRow:,以及名为类型委托的弱属性。id<SimpleTableViewControllerDelegate>..这就是我们将选择传递回父控制器的方式。在SimpleTableViewController.m中,实现tableview数据源和委托方法,调用itemSelectedatRow:在……里面tableView:didSelectRowAtIndexPath:.这种方法具有相当可重用的额外好处。若要使用,请在ViewController.h中导入SimpleTableViewController类,遵循SimpleTableViewDelegate,并实现itemSelectedAtRow:方法。然后,要打开该模型,只需实例化一个新的SimpleTableViewController,设置表数据和委托,并呈现它。UINavigationController&nbsp;*navigationController&nbsp;=&nbsp;(UINavigationController&nbsp;*)[self.storyboard&nbsp;instantiateViewControllerWithIdentifier: @"SimpleTableVC"];SimpleTableViewController&nbsp;*tableViewController&nbsp;=&nbsp;(SimpleTableViewController&nbsp;*)[[navigationController&nbsp;viewControllers] &nbsp;objectAtIndex:0];tableViewController.tableData&nbsp;=&nbsp;self.statesArray;tableViewController.navigationItem.title&nbsp;=&nbsp;@"States"; &nbsp;tableViewController.delegate&nbsp;=&nbsp;self;[self&nbsp;presentViewController:navigationController&nbsp;animated:YES&nbsp;completion:nil];我创建了一个简单的例子张贴在GitHub上.亦见显示操作表会导致CGContext无效上下文错误.
打开App,查看更多内容
随时随地看视频慕课网APP