有没有关于如何在 iOS 上使用 UIPopoverController 的例子?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5744434/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 19:39:35  来源:igfitidea点击:

Are there examples of how to use UIPopoverController on iOS?

iphoneiosipaduipopovercontroller

提问by Nick Weaver

I've seen some demos where UIPopoverController is used and would like to use it in my apps.

我看过一些使用 UIPopoverController 的演示,并希望在我的应用程序中使用它。

So does anyone have any good tutorials that you could link me?

那么有没有人有任何好的教程可以链接我?

Is it possible to use it in relation to UISegmentedControl where different popover windows are summoned when different segments are selected as a type of a switch view function?

Is it possible to use it in relation to UISegmentedControl where different popover windows are summoned when different segments are selected as a type of a switch view function?

回答by Bhupendrasingh Lohar

  1. For popover in iPad we can use ActionSheetStringPicker, and for implementing it in your project you need to import ActionSheetStringPicker into your controller. like - #imaport "ActionSheetStringPicker.h"

  2. After importing this you have to create an array which has only string type value.

  1. 对于 iPad 中的 popover,我们可以使用 ActionSheetStringPicker,为了在您的项目中实现它,您需要将 ActionSheetStringPicker 导入到您的控制器中。喜欢 - #imaport "ActionSheetStringPicker.h"

  2. 导入后,您必须创建一个只有字符串类型值的数组。

e.g.

例如

   NSArray *sourceArray=[[NSArray alloc]initWithObjects:@"Take Photo",@"Choose Photo", nil];
  1. And last you have to implement below method.

    [ActionSheetStringPicker showPickerWithTitle:@"Any title"
                                                rows:sourceArray
                                    initialSelection:yourInitialSelectionIntValue
                                           doneBlock:^(ActionSheetStringPicker *picker, NSInteger selectedIndex, id selectedValue) {
    
                                           NSLog(@" Index : %ld, value : %@",
                                                 (long)selectedIndex, selectedValue);
                                           if ([selectedValue isEqualToString:@"Choose Photo"]) {
    
                                               // open photo lib
                                               [self youerMethdeOpenPhotoLib];
    
                                           }
                                           else
                                           {
                                               // open Camera
                                               [self yourMethodOpenCamera];
                                           }
    
    
    
                                       }
                                     cancelBlock:^(ActionSheetStringPicker *picker) {
                                         NSLog(@"Select photo Cancel");
    
                                     }origin:YourTapButtonObject];
    
  1. 最后你必须实现下面的方法。

    [ActionSheetStringPicker showPickerWithTitle:@"Any title"
                                                rows:sourceArray
                                    initialSelection:yourInitialSelectionIntValue
                                           doneBlock:^(ActionSheetStringPicker *picker, NSInteger selectedIndex, id selectedValue) {
    
                                           NSLog(@" Index : %ld, value : %@",
                                                 (long)selectedIndex, selectedValue);
                                           if ([selectedValue isEqualToString:@"Choose Photo"]) {
    
                                               // open photo lib
                                               [self youerMethdeOpenPhotoLib];
    
                                           }
                                           else
                                           {
                                               // open Camera
                                               [self yourMethodOpenCamera];
                                           }
    
    
    
                                       }
                                     cancelBlock:^(ActionSheetStringPicker *picker) {
                                         NSLog(@"Select photo Cancel");
    
                                     }origin:YourTapButtonObject];