zoukankan      html  css  js  c++  java
  • iPhone: 在 iPhone app 里使用 UIPopoverController

     更新:iOS8 版本已经不可用

    为 UIPopoverController 增加类别,如下:

    //NSObject+UIPopover_Iphone.h
    
    #import <Foundation/Foundation.h>
    
    @interface UIPopoverController (overrides)
    +(BOOL)_popoversDisabled;
    @end
    
    
    //NSObject+UIPopover_Iphone.m
    
    #import "NSObject+UIPopover_Iphone.h"
    
    @implementation UIPopoverController (overrides)
    
    +(BOOL)_popoversDisabled
    {
        return NO;
    }
    
    @end

    在要使用的 ViewController 中,导入头文件 NSObject+UIPopover_Iphone.h,便可正常使用。

    注意

    需要注意的是,保持将要显示的 popoverViewController 的引用,否则在 ARC 中无法使用,具体表现如下

    *** Terminating app due to uncaught exception 'NSGenericException', 
    reason: '-[UIPopoverController dealloc] reached while popover is still visible.'

    与此相似的有,创建一个 UIWindow,如果没有保持对 UIWindow 的引用,当 makeKeyAndVisible 后,window 只会一闪而过。

    想必这种一定不是想要的效果。

    使用

    - (IBAction)moreItemClicked:(id)sender
    {
        UITableViewController *detailController = [self.storyboard instantiateViewControllerWithIdentifier:@"MorePopover"];
        //hanlde tableview delegate in this class
        detailController.tableView.delegate = self;
        
        UIPopoverController *popoverController = nil;
        popoverController = [[UIPopoverController alloc] initWithContentViewController:detailController];
        popoverController.delegate = self;
        popoverController.popoverContentSize = CGSizeMake(140, 88);
        [popoverController presentPopoverFromBarButtonItem:sender permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
        self.poc = popoverController;
    }

    效果

  • 相关阅读:
    C# zip压缩文件的功能
    C#图解教程 第四章 第五章
    process.StandardOutput.ReadToEnd() 假死
    C# 图解教程 (类型 存储和变量)
    unity editor下选中GameObject粘贴复制pos信息
    Texture中指定具体颜色进行高亮显示
    unity 加载Assetbundle文件夹路径需要注意
    unity 文件移动注意 AB打包文件名注意小写
    linux总结应用之三 建立内核
    linux总结应用之二
  • 原文地址:https://www.cnblogs.com/ihojin/p/iphone-uipopovercontroller.html
Copyright © 2011-2022 走看看