首页 \ 问答 \ python中的泛型方法(Generic methods in python)

python中的泛型方法(Generic methods in python)

是否有可能在Python中实现泛型方法处理程序,它允许调用不存在的函数? 像这样的东西:

class FooBar:
  def __generic__method__handler__(.., methodName, ..):
    print methodName

fb = FooBar()
fb.helloThere()

-- output --
helloThere

Is it possible to implement generic method handlers in python which allow for calling of non-existent functions? Something like this:

class FooBar:
  def __generic__method__handler__(.., methodName, ..):
    print methodName

fb = FooBar()
fb.helloThere()

-- output --
helloThere

原文:https://stackoverflow.com/questions/6467461
更新时间:2023-08-14 06:08

最满意答案

你如此亲密,只要做到以下几点。

保留split视图布局的细节segues,并为以下方法返回true,并删除其余代码以处理变量collapseDetailViewController

func splitViewController(splitViewController: UISplitViewController, collapseSecondaryViewController secondaryViewController: UIViewController, ontoPrimaryViewController primaryViewController: UIViewController) -> Bool {
return true    
}

将以下内容放在Master View控制器中

self.splitViewController!.delegate = self;

self.splitViewController!.preferredDisplayMode = UISplitViewControllerDisplayMode.AllVisible

self.extendedLayoutIncludesOpaqueBars = true  

self.extendedLayoutIncludesOpaqueBars = true添加到上一个答案中提到的详细视图控制器中。 这应该删除视图控制器上出现的栏。

另外如果你想要一些额外的功能,如果你想让你的详细视图在iPad上使用全屏,请添加以下内容。

navigationItem.leftBarButtonItem = splitViewController?.displayModeButtonItem()
navigationItem.leftItemsSupplementBackButton = true

You are so close just do the following.

Keep the split view layout with detail segues and return true for the following method and remove the rest of the code to do with the variable collapseDetailViewController.

func splitViewController(splitViewController: UISplitViewController, collapseSecondaryViewController secondaryViewController: UIViewController, ontoPrimaryViewController primaryViewController: UIViewController) -> Bool {
return true    
}

Put the following in you Master View controller

self.splitViewController!.delegate = self;

self.splitViewController!.preferredDisplayMode = UISplitViewControllerDisplayMode.AllVisible

self.extendedLayoutIncludesOpaqueBars = true  

Add self.extendedLayoutIncludesOpaqueBars = true to your detail view controller as mentioned by the previous answer. That should remove the bar appearing on your view controllers.

Also if you want some extra functionality add the following if you want your detail view to use the full screen on iPad.

navigationItem.leftBarButtonItem = splitViewController?.displayModeButtonItem()
navigationItem.leftItemsSupplementBackButton = true

相关问答

更多
  • 我找到了一个解决方案,诀窍是删除segue并使用这样的故事板引用: 出于测试和教学目的,我创建了一个完整的测试项目, 可从GitHub获得 。 这演示了使用多个故事板进行详细视图。 11月28日更新:此解决方案有效,但需要iOS 9.完全可以使用另一个UIViewController作为DetailViewController(意味着可以使用模板),只要你删除segue,实现tableView: didSelectRowAtIndexPath并使用示例中的代码。 在后一种情况下,它也适用于iOS 8。 I ...
  • 你如此亲密,只要做到以下几点。 保留split视图布局的细节segues,并为以下方法返回true,并删除其余代码以处理变量collapseDetailViewController 。 func splitViewController(splitViewController: UISplitViewController, collapseSecondaryViewController secondaryViewController: UIViewController, ontoPrimaryViewCont ...
  • UISplitViewController不支持此UISplitViewController 。 如果您需要这种UI,通常会创建一个自定义设置来实现此目的。 我使用两个UINavigationController构建一个设置,使用我的App Delegate控制它,然后从那里获取它。 处理轮换时会有一些额外的工作,但在进行自定义操作时可以预料到这一点。 这不应该太难 。 This is not supported by the UISplitViewController. If you need this ...
  • 我被困在一个类似的问题上。 关闭尺寸类别为我固定。 在故事板的右侧窗格中,单击“显示文件检查器”(纸张图标),并取消选中自动布局设置下方的“使用大小类别”。 I was stuck on a similar issue. Turning off size classes fixed it for me. In the storyboard, on the right pane, click "Show the file inspector" (paper looking icon), and uncheck ...
  • 也许这个问题有帮助吗? UISplitViewController必须是应用程序的根视图控制器 Maybe this question will help? A UISplitViewController must be the root view controller of your application
  • 如果您希望将您的应用批准为在App Store上发布,则无法这样做。 如果你使用的是Enterprise发行版,或者只是搞乱了,你可能会得到这个工作: 为您的项目添加一个新视图(NewView) 将视图层次结构从SplitViewController视图复制到NewView中 像正常一样将NewView推入您的导航控制器堆栈 尽管如此,你将无法找到很多帮助,因为这是浪费精力(苹果公司不会允许它)。 If you hope to get your app approved for distribution o ...
  • 如果你想用navigationController做,那就试试吧: func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: NSDictionary?) -> Bool { if UIDevice.current.userInterfaceIdiom == .pad { self.window = UIWindow(frame: UIScreen.mainScr ...
  • 我假设detail["image"]包含的detail["image"]位于应用程序包中(即:不是来自HTTP URL的图像)。 因此,您应该使用UIImage的init(named:)构造函数来加载图像。 像这样的东西: if let myImage = UIImage(named: detail["image"]) { myImageView.image = myImage } 编辑: 这也是您的代码在configureView更好地管理选项和强制转换: func configureView( ...
  • 你不应该试着这样做: 拆分视图控制器必须始终是您创建的任何接口的根。 换句话说,您必须始终从UISplitViewController对象安装视图作为应用程序窗口的根视图。 你可以在这里阅读更多相关信息 You should not try to do that: A split view controller must always be the root of any interface you create. In other words, you must always install the vi ...
  • UISplitViewController使用大小类来确定如何显示其主视图和详细视图控制器。 当您的UISplitViewController具有horizontalSizeClass和verticalSizeClass Regular时,它将在同一屏幕上显示Master和Detail视图控制器。 您需要将拆分视图控制器嵌入到容器视图控制器中,以覆盖默认大小类,如我在此处所述 。 您还必须检查设备方向,以便在Compact(纵向)或Regular(横向)横向尺寸等级之间进行分叉: class Contain ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。