【问题标题】:Setting UISwitch state in UIPopoverController在 UIPopoverController 中设置 UISwitch 状态
【发布时间】:2011-07-21 12:24:31
【问题描述】:

我想从我的 MainViewController 中重置 UIPopoverController 中的 UISwitch 的状态。我假设一个简单的

popoverView.switchName.on = NO;

不会做这项工作(因为它似乎没有工作)。最好的方法是什么? 谢谢。

【问题讨论】:

  • 我在回答中做了一些假设。如果我错过了重点,请告诉我;)

标签: ios ipad uipopovercontroller uiswitch


【解决方案1】:

UIPopoverController 是框架内显示的内容视图控制器的容器。我假设您在某个时候打电话给initWithContentViewController 具有呈现内容的视图控制器,并且该视图控制器具有 switchName 属性。

要访问此视图控制器,您可以使用 UIPopoverController 的 contentViewController 属性。我想它会是这样的:

// assuming popoverView is a UIPopoverController and that the type of 
// the view contorller you pass to initWithContentViewController is YourViewController
YourViewController * myController = (YourViewController*)popoverView.contentViewController;
myController.switchName.on = NO;

【讨论】:

  • 感谢您的快速回答。是的,我正在调用 initWithContentViewController ,是的 switchName 是一个属性。我尝试了您的建议,但不幸的是这似乎也不起作用。 popoverView.contentViewController.switchName 似乎不是一个有效的结构。
  • @erno-simonyi 啊!您必须将 contentViewController 转换为您的 UIViewController 子类(我称之为 YourViewController)。考虑到这一点,我已经更新了我的答案。
  • 谢谢,我一回家就试试。
  • 抱歉耽搁了最近没有太多时间。现在试了一下,效果很好。非常感谢。
  • @erno-simonyi 没问题。很高兴你把它整理好了。
猜你喜欢
  • 2017-01-07
  • 1970-01-01
  • 1970-01-01
  • 2012-04-25
  • 2018-10-25
  • 2018-04-04
  • 1970-01-01
  • 1970-01-01
  • 2020-04-09
相关资源
最近更新 更多