弹出窗口未出现在 iOS 中

Posted

技术标签:

【中文标题】弹出窗口未出现在 iOS 中【英文标题】:Pop-Up not appearing in iOS 【发布时间】:2013-09-17 11:40:11 【问题描述】:

我正在尝试在单击按钮时创建一个名为“添加注释”的简单弹出窗口,该弹出窗口有一个保存和取消按钮,用于保存用户创建的注释并取消弹出窗口。这是弹出式课程

AddNotesPopUp.h

#import <UIKit/UIKit.h>
#import "UIImage+Buttons.h"


typedef enum AddNotesViewType

    AddNotesPopUpSimple
AddNotesPopUpType;

@protocol AddNotesDelegate<NSObject>

@optional
-(void)saveButtonClicked:(id) popUp;
-(void)cancelAddButtonClicked:(id)popUp;
@end

@interface AddNotesPopUp : UIView

@property AddNotesPopUpType atype;
@property (nonatomic,assign) id <AddNotesDelegate> delegate;

-(id)initWithDelegate:(id)parent type:(AddNotesPopUpType) type;

@property (weak, nonatomic) IBOutlet UIView *popView;
@property (strong, nonatomic) IBOutlet UIButton *titleButton;


@property (weak, nonatomic) IBOutlet UIButton *cancelAddButton;
@property (weak, nonatomic) IBOutlet UIButton *saveButton;
@property (weak, nonatomic) IBOutlet UITextView *textArea;


- (IBAction)saveButtonAction:(id)sender;

- (IBAction)cancelButtonAction:(id)sender;

-(void)show;
-(void)hide;

@end

AddNotesPopUp.m

#import "AddNotesPopUp.h"
#import <QuartzCore/QuartzCore.h>


@implementation AddNotesPopUp

- (id)initWithFrame:(CGRect)frame

    self = [super initWithFrame:frame];
    if (self) 
        // Initialization code
        self=(AddNotesPopUp*)[[[NSBundle mainBundle] loadNibNamed:@"AddNotesPopUp" owner:nil options:nil] lastObject];
    
    return self;

-(id)initWithDelegate:(id)parent type:(AddNotesPopUpType) type


    if (self = [super initWithFrame:CGRectMake(0, 0, 300, 300)])
    
        // Initialization code
          self=(AddNotesPopUp*)[[[NSBundle mainBundle] loadNibNamed:@"AddNotesPopUp" owner:nil options:nil] lastObject];
    
    self.delegate=parent;
    self.atype=type;
    UIViewController *parentView=(UIViewController*)parent;
    [parentView.view addSubview:self];
         if (type==AddNotesPopUpSimple)
        
    [self.titleButton setImage:[UIImage buttonWithText:@"Add Notes" fontSize:15 bold:YES buttonSize:self.titleButton.frame.size baseColor:[UIColor colorWithRed:73.0/255.0 green:90.0/255.0 blue:100.0/255.0 alpha:1] downTo:[UIColor colorWithRed:57.0/255.0 green:70.0/255.0 blue:77.0/255.0 alpha:1]] forState:UIControlStateNormal];
    [self.saveButton setImage:[UIImage buttonWithTextAlignCenter:@"Save" fontSize:15 bold:YES buttonSize:self.saveButton.frame.size baseColor:[UIColor colorWithRed:117.0/255.0 green:185.0/255.0 blue:83.0/255.0 alpha:1] downTo:[UIColor colorWithRed:95.0/255.0 green:144.0/255.0 blue:64.0/255.0 alpha:1]] forState:UIControlStateNormal];
    [self.cancelAddButton setImage:[UIImage buttonWithTextAlignCenter:@"Cancel" fontSize:15 bold:YES buttonSize:self.cancelAddButton.frame.size baseColor:[UIColor colorWithRed:174.0/255.0 green:174.0/255.0 blue:174.0/255.0 alpha:1] downTo:[UIColor colorWithRed:124.0/255.0 green:124.0/255.0 blue:124.0/255.0 alpha:1]] forState:UIControlStateNormal];
        


    self.popView.layer.masksToBounds=YES;
    self.popView.layer.cornerRadius=5.0f;
    self.popView.layer.borderWidth=1.0f;
    self.popView.layer.borderColor=[[UIColor blackColor]CGColor];
    self.popView.hidden=YES;


    self.hidden=YES;
    self.textArea.hidden=YES;


    return self;


-(void)show

    self.popView.hidden=NO;
    self.textArea.hidden=NO;
    [self.popView setTransform:CGAffineTransformMakeScale(0.1,0.1)];
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:0.25];
    [self.popView setTransform:CGAffineTransformMakeScale(1.0,1.0)];
    [UIView commitAnimations];




-(void) hide

    self.popView.hidden=YES;


- (IBAction)saveButtonAction:(id)sender 
    [self.delegate saveButtonClicked:self];


- (IBAction)cancelButtonAction:(id)sender 

    [self.delegate cancelAddButtonClicked:self];

@end

这就是我在视图控制器按钮操作中调用弹出窗口的方式

- (IBAction)addNotes:(id)sender 

    AddNotesPopUp *pop=[[AddNotesPopUp alloc] initWithDelegate:self type:AddNotesPopUpSimple];
    [pop show];

我已经检查了断点,并且执行成功通过了 AddNotesPopUp.m 中的 initwithDelegate 和 show 方法,但是没有出现弹出窗口,我在这里缺少什么?我已经在我的视图控制器中添加了 AddNotesPopUp 的代表和类,我也没有收到任何错误。我正在使用 Xcode 4.6。有什么建议吗?

【问题讨论】:

代码看起来很乱 self.delegate=parent;是两倍 [parentView.view addSubview:self];是两次。此外,您使用 initWithFrame 之后,您将使用从 loadNibNamed 获取的实例覆盖它。 抱歉,我只是在我的代码中进行一些故障排除。 self.delegate=parent 的一部分实际上已被注释 【参考方案1】:

原来这是一个简单的问题,我只需要添加 自我隐藏=否;在show方法中

【讨论】:

以上是关于弹出窗口未出现在 iOS 中的主要内容,如果未能解决你的问题,请参考以下文章

SwiftUI超便捷在iOS16中弹出App用户评价(Review)小窗口

iOS:获取本机弹出窗口时未获取 touchesCancelled

Apple Pay 弹出窗口未显示特定的默认送货地址

如何在asp.net中弹出可编辑的窗口

Jquery EasyUI的Dialog 怎么在iframe中弹出和不在iframe中弹出一样在窗口最顶层?

ext中弹出新增/编辑窗口后还能对其他非本窗口内容进行操作,怎样限制除弹出框外其他都不可操作呢?