簡體   English   中英

彈出窗口未出現在iOS中

[英]Pop-Up not appearing in iOS

我試圖在單擊按鈕時創建一個名為“添加注釋”的簡單彈出窗口,該彈出窗口具有保存和取消按鈕,以保存用戶創建的注釋並取消彈出窗口。 這是彈出類

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

這就是我在viewcontroller按鈕操作中調用彈出窗口的方式

- (IBAction)addNotes:(id)sender {

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

我已經檢查了斷點,執行成功通過initwithDelegate並在AddNotesPopUp.m中顯示了方法,但是沒有出現彈出窗口,我在這里錯過了什么? 我已經在我的viewcontroller中添加了AddNotesPopUp的委托和類,並且我也沒有收到任何錯誤。 我正在使用Xcode 4.6。 有什么建議么?

原來這是一個簡單的問題,我只需要添加self.hidden = NO; 在show方法中

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM